2013-06-28 1 views
0

У меня есть три файла XML в папке, а также один файл XSD для них. Пользователь помещает в папку несколько файлов XML, и мне нужно проверить, что они правильные, используя документ схемы. Сами файлы XML не содержат ссылки внутри них в любой файл XSD.Access 2003 VBA - Проверка XML-схемы XSD & DOM

  • Переменная AwardsXSDPath путь к файлу схемы
  • Переменная strFileName является путь к файлу XML обрабатываемый
  • Переменная StrFileList представляет собой массив со списком всех файлов XML, чтобы быть проверены

у меня есть цикл, который принимает каждый файл в свою очередь, и пытается проверить их против XSD; -

'verify the schemas of the three XML files using the XSD file 
For intFile = 1 To UBound(strFileList) 
    strFileName = ImportFolder & strFileList(intFile) 
    'Debug.Print strFileName 


    objSchemaCache.Add "http://somewhere.com/root", LoadXmlFile(AwardsXSDPath) 

    Set xmlDoc = LoadXmlFile(strFileName) 
    Set xmlDoc.schemas = objSchemaCache 
    Set objErr = xmlDoc.validate() 


    If objErr.errorCode = 0 Then 
     Debug.Print "No errors found" 
    Else 
     Debug.Print "Error parser: " & objErr.errorCode & "; " & objErr.reason 
    End If 

    Set xmlDoc = Nothing 
    Set objErr = Nothing 

Next intFile 

У меня есть функция под названием LoadXmlFile

Function LoadXmlFile(Path As String) As MSXML2.DOMDocument60 
    Set LoadXmlFile = New MSXML2.DOMDocument60 

    With LoadXmlFile 
     .async = False 
     .validateOnParse = False 
     .resolveExternals = False 
     .Load Path 
    End With 
End Function 

Непосредственным окно показывает ошибку

анализатор ошибки: -1072897500; Узел не является ни действительным, ни недопустимым , потому что объявления DTD/Schema не найдены.

Я предполагаю, что это означает, что XML-файл, о котором идет речь, не имеет декларации схемы. У меня нет объявлений схемы в самих файлах XML, поскольку они не поставляются с одним. Не существует способа проверить файлы XML в XSD без объявления shcema в самих файлах?

XSD-файл; -

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" 
      elementFormDefault="qualified" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="Awards"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element name="Header"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element name="FinAssType"  type="xs:string" /> 
       <xs:element name="FileType"   type="xs:string" /> 
       <xs:element name="ExtractDateTime" type="xs:dateTime" /> 
       <xs:element name="AwardsFrom"  type="xs:date" /> 
       <xs:element name="AwardsTo"   type="xs:date" minOccurs="0" /> 
       <xs:element name="LACode"   type="xs:int" minOccurs="0" /> 
       <xs:element name="OrganisationName" type="xs:string" /> 
       <xs:element name="SupplierDetails"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="SupplierID"  type="xs:int" /> 
        <xs:element name="SupplierName"  type="xs:string" /> 
        <xs:element name="SupplierAddress" type="xs:string" /> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     <xs:element name="Records" maxOccurs="unbounded"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element name="CaseIdentification"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="CaseReference"  type="xs:string" /> 
        <xs:element name="DateOfApplication" type="xs:date" /> 
        <xs:element name="ReasonForApplication" type="xs:string" /> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="ApplicantDetails"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="ApplicantTitle"  type="xs:string" /> 
        <xs:element name="ApplicantForename" type="xs:string" /> 
        <xs:element name="ApplicantSurname" type="xs:string" /> 
        <xs:element name="ApplicantNINO"  type="xs:string" /> 
        <xs:element name="DateOfBirth"  type="xs:date" /> 
        <xs:element name="ApplicantAddress1" type="xs:string" /> 
        <xs:element name="ApplicantAddress2" type="xs:string" /> 
        <xs:element name="ApplicantAddress3" type="xs:string" minOccurs="0" /> 
        <xs:element name="ApplicantAddress4" type="xs:string" minOccurs="0" /> 
        <xs:element name="ApplicantPostcode" type="xs:string" minOccurs="0" /> 
        <xs:element name="ApplicantTelNo"  type="xs:string" minOccurs="0" /> 
        <xs:element name="ApplicantEmail"  type="xs:string" minOccurs="0" /> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="NewAddressDetails" minOccurs="0" > 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="NewAddressMoveDate" type="xs:date" /> 
        <xs:element name="NewAddress1"  type="xs:string" /> 
        <xs:element name="NewAddress2"  type="xs:string" /> 
        <xs:element name="NewAddress3"  type="xs:string" minOccurs="0" /> 
        <xs:element name="NewAddress4"  type="xs:string" minOccurs="0" /> 
        <xs:element name="NewAddressPostcode" type="xs:string" minOccurs="0" /> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="ThirdPartyContact"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="ThirdPartyRelationship" type="xs:string" /> 
        <xs:element name="ThirdPartyName"   type="xs:string" /> 
        <xs:element name="ThirdPartyAddressLine1" type="xs:string" /> 
        <xs:element name="ThirdPartyAddressLine2" type="xs:string" /> 
        <xs:element name="ThirdPartyAddressLine3" type="xs:string" minOccurs="0" /> 
        <xs:element name="ThirdPartyAddressLine4" type="xs:string" minOccurs="0" /> 
        <xs:element name="ThirdPartyPostCode"  type="xs:string" minOccurs="0" /> 
        <xs:element name="ThirdPartyTelNo"  type="xs:string" minOccurs="0" /> 
        <xs:element name="ThirdPartyEmail"  type="xs:string" minOccurs="0" /> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
       <xs:element name="ClaimDetails"> 
       <xs:complexType> 
        <xs:sequence> 
        <xs:element name="ItemRequested"> 
         <xs:complexType> 
         <xs:sequence> 
          <xs:element name="ClaimID"   type="xs:int" /> 
          <xs:element name="AssistanceType" type="xs:string" /> 
          <xs:element name="GoodsType"  type="xs:string" /> 
          <xs:element name="AmountRequested" type="xs:decimal" minOccurs="0" /> 
          <xs:element name="ItemQuantity"  type="xs:int" /> 
         </xs:sequence> 
         </xs:complexType> 
        </xs:element> 
        <xs:element name="AwardDetail"> 
         <xs:complexType> 
         <xs:sequence> 
          <xs:element name="AwardDate"  type="xs:date" /> 
          <xs:element name="AwardValue"  type="xs:decimal" /> 
          <xs:element name="QuantityAwarded" type="xs:int" /> 
          <xs:element name="TotalAwardValue" type="xs:decimal" /> 
          <xs:element name="PaymentType"  type="xs:string" /> 
          <xs:element name="Recoverable"  type="xs:boolean" /> 
          <xs:element name="Reference1Name" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference1Value" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference2Name" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference2Value" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference3Name" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference3Value" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference4Name" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference4Value" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference5Name" type="xs:string" minOccurs="0" /> 
          <xs:element name="Reference5Value" type="xs:string" minOccurs="0" /> 
         </xs:sequence> 
         </xs:complexType> 
        </xs:element> 
        </xs:sequence> 
       </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     <xs:element name="Trailer"> 
      <xs:complexType> 
      <xs:sequence> 
       <xs:element name="NoOfRecords"  type="xs:int" /> 
       <xs:element name="TotalOfAwardValues" type="xs:decimal" /> 
      </xs:sequence> 
      </xs:complexType> 
     </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

Один из файлов XML ниже

<?xml version="1.0" encoding="UTF-8"?> 
<Awards> 
    <Header> 
    <FinAssType>XXX</FinAssType> 
    <FileType>Awards</FileType> 
    <ExtractDateTime>2013-04-03T16:50:15.483</ExtractDateTime> 
    <LACode /> 
    <OrganisationName>Org</OrganisationName> 
    <SupplierDetails> 
     <SupplierID>3</SupplierID> 
     <SupplierName>xxx</SupplierName> 
     <SupplierAddress>xxx</SupplierAddress> 
    </SupplierDetails> 
    </Header> 
    <AwardRecords> 
    <CaseIdentification> 
     <CaseReference>XXX1156</CaseReference> 
     <DateOfApplication>2013-03-30</DateOfApplication> 
     <ReasonForApplication>Moving Home/Resettlement</ReasonForApplication> 
    </CaseIdentification> 
    <ApplicantDetails> 
     <ApplicantTitle>Mr</ApplicantTitle> 
     <ApplicantForename>test</ApplicantForename> 
     <ApplicantSurname>test</ApplicantSurname> 
     <ApplicantNINO>XX999999X</ApplicantNINO> 
     <DateOfBirth>1984-03-03</DateOfBirth> 
     <ApplicantAddress1>12</ApplicantAddress1> 
     <ApplicantAddress2>1</ApplicantAddress2> 
     <ApplicantAddress3>3</ApplicantAddress3> 
     <ApplicantAddress4>3</ApplicantAddress4> 
     <ApplicantPostcode>m16 7ha</ApplicantPostcode> 
     <ApplicantTelNo>01611234567</ApplicantTelNo> 
     <ApplicantEmail>[email protected]</ApplicantEmail> 
     <DateMovedIn>1991-11-28</DateMovedIn> 
    </ApplicantDetails> 
    <ClaimDetails> 
     <Claim> 
     <ItemRequested> 
      <ClaimID>20</ClaimID> 
      <AssistanceType>Beds and mattresses</AssistanceType> 
      <GoodsType>Double bed (standard mattress)</GoodsType> 
      <ItemQuantity>1</ItemQuantity> 
     </ItemRequested> 
     <AwardDetail> 
      <AwardDate>2013-03-30T11:33:27.307</AwardDate> 
      <AwardValue>134.03</AwardValue> 
      <QuantityAwarded>1</QuantityAwarded> 
      <TotalAwardValue>134.03</TotalAwardValue> 
      <PaymentType>Delivery to customer</PaymentType> 
      <Recoverable>0</Recoverable> 
      <Reference1Name>Delivery/accessibility info</Reference1Name> 
      <Reference1Value /> 
      <Reference2Name>Notes</Reference2Name> 
      <Reference2Value /> 
      <Reference3Value /> 
      <Reference4Value /> 
      <Reference5Value /> 
     </AwardDetail> 
     </Claim> 
    </ClaimDetails> 
    </AwardRecords> 
    <AwardRecords> 
    <CaseIdentification> 
     <CaseReference>XXX1483</CaseReference> 
     <DateOfApplication>2013-04-03</DateOfApplication> 
     <ReasonForApplication>xxx</ReasonForApplication> 
    </CaseIdentification> 
    <ApplicantDetails> 
     <ApplicantTitle>Ms</ApplicantTitle> 
     <ApplicantForename>xxx</ApplicantForename> 
     <ApplicantSurname>xxx</ApplicantSurname> 
     <ApplicantNINO>xxx</ApplicantNINO> 
     <DateOfBirth>1959-04-25</DateOfBirth> 
     <ApplicantAddress1>xxx</ApplicantAddress1> 
     <ApplicantAddress2>xxx</ApplicantAddress2> 
     <ApplicantAddress3>xxx</ApplicantAddress3> 
     <ApplicantAddress4 /> 
     <ApplicantPostcode>xxx</ApplicantPostcode> 
     <ApplicantTelNo>xxx</ApplicantTelNo> 
     <ApplicantEmail /> 
     <DateMovedIn>2013-04-02</DateMovedIn> 
    </ApplicantDetails> 
    <ClaimDetails> 
     <Claim> 
     <ItemRequested> 
      <ClaimID>88</ClaimID> 
      <AssistanceType>xxx</AssistanceType> 
      <GoodsType>xxx</GoodsType> 
      <ItemQuantity>1</ItemQuantity> 
     </ItemRequested> 
     <AwardDetail> 
      <AwardDate>2013-04-03T15:54:55.100</AwardDate> 
      <AwardValue>134.03</AwardValue> 
      <QuantityAwarded>1</QuantityAwarded> 
      <TotalAwardValue>134.03</TotalAwardValue> 
      <PaymentType>Delivery to customer</PaymentType> 
      <Recoverable>0</Recoverable> 
      <Reference1Name>xxx</Reference1Name> 
      <Reference1Value /> 
      <Reference2Name>Notes</Reference2Name> 
      <Reference2Value>xxx</Reference2Value> 
      <Reference3Value /> 
      <Reference4Value /> 
      <Reference5Value /> 
     </AwardDetail> 
     </Claim> 
    </ClaimDetails> 
    </AwardRecords> 
    <Trailer> 
    <NoOfRecords>2</NoOfRecords> 
    <TotalOfAwardValues>268</TotalOfAwardValues> 
    </Trailer> 
</Awards> 

Кроме того, после того, как я проверил с помощью схемы, я буду нуждаться в дальнейшем цикл для перебора через файлы и сохранить содержимое узла «Награды/Заголовки/ПоставщикДетали/Имя поставщика» - как я могу это сделать?

Спасибо.

ответ