title: Access 2003 VBA - Validate XML schema XSD & DOM
body: <p>I have three XML files in a folder, and also have the one XSD file for these. The user places a number of XML files into the folder, and I need to check they are the correct ones using the schema doc. The XML files themselves do not contain a link within them to any XSD file.</p>
  
  <ul>
  <li>The AwardsXSDPath variable is the path to the schema file </li>
  <li>The strFileName variable is the path of the XML file being processed</li>
  <li>The StrFileList variable is an array listing each XML file to be
  checked</li>
  </ul>
  
  <p>I have a loop which takes each file in turn and tries to validate them against the XSD ;-</p>
  
  <pre><code>'verify the schemas of the three XML files using the XSD file
  For intFile = 1 To UBound(strFileList)
      strFileName = ImportFolder &amp; 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: " &amp; objErr.errorCode &amp; "; " &amp; objErr.reason
      End If
  
      Set xmlDoc = Nothing
      Set objErr = Nothing
  
  Next intFile
  </code></pre>
  
  <p>I have a function called LoadXmlFile</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The immediate window is showing an error </p>
  
  <blockquote>
    <p>Error parser: -1072897500; The node is neither valid nor invalid
    because no DTD/Schema declaration was found.</p>
  </blockquote>
  
  <p>I assume this means that the XML file in question has no scheme declaration. I don't have schema declarations in the XML files themselves as they do not come with one. Isn't there a way to verify the XML files to the XSD without having a shcema declaration in the files themselves?</p>
  
  <p>The XSD file ;-</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema attributeFormDefault="unqualified" 
             elementFormDefault="qualified" 
             xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="Awards"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="Header"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="FinAssType"       type="xs:string" /&gt;
                &lt;xs:element name="FileType"         type="xs:string" /&gt;
                &lt;xs:element name="ExtractDateTime"  type="xs:dateTime" /&gt;
                &lt;xs:element name="AwardsFrom"       type="xs:date" /&gt;
                &lt;xs:element name="AwardsTo"         type="xs:date"  minOccurs="0" /&gt;
                &lt;xs:element name="LACode"           type="xs:int"   minOccurs="0" /&gt;
                &lt;xs:element name="OrganisationName" type="xs:string" /&gt;
                &lt;xs:element name="SupplierDetails"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="SupplierID"       type="xs:int" /&gt;
                      &lt;xs:element name="SupplierName"     type="xs:string" /&gt;
                      &lt;xs:element name="SupplierAddress"  type="xs:string" /&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
          &lt;xs:element name="Records" maxOccurs="unbounded"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="CaseIdentification"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="CaseReference"        type="xs:string" /&gt;
                      &lt;xs:element name="DateOfApplication"    type="xs:date" /&gt;
                      &lt;xs:element name="ReasonForApplication" type="xs:string" /&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
                &lt;xs:element name="ApplicantDetails"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="ApplicantTitle"     type="xs:string" /&gt;
                      &lt;xs:element name="ApplicantForename"  type="xs:string" /&gt;
                      &lt;xs:element name="ApplicantSurname"   type="xs:string" /&gt;
                      &lt;xs:element name="ApplicantNINO"      type="xs:string" /&gt;
                      &lt;xs:element name="DateOfBirth"        type="xs:date" /&gt;
                      &lt;xs:element name="ApplicantAddress1"  type="xs:string" /&gt;
                      &lt;xs:element name="ApplicantAddress2"  type="xs:string" /&gt;
                      &lt;xs:element name="ApplicantAddress3"  type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ApplicantAddress4"  type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ApplicantPostcode"  type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ApplicantTelNo"     type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ApplicantEmail"     type="xs:string" minOccurs="0" /&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
                &lt;xs:element name="NewAddressDetails" minOccurs="0" &gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="NewAddressMoveDate" type="xs:date"    /&gt;
                      &lt;xs:element name="NewAddress1"        type="xs:string"  /&gt;
                      &lt;xs:element name="NewAddress2"        type="xs:string"  /&gt;
                      &lt;xs:element name="NewAddress3"        type="xs:string"  minOccurs="0" /&gt;
                      &lt;xs:element name="NewAddress4"        type="xs:string"  minOccurs="0" /&gt;
                      &lt;xs:element name="NewAddressPostcode" type="xs:string"  minOccurs="0" /&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
                &lt;xs:element name="ThirdPartyContact"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="ThirdPartyRelationship" type="xs:string" /&gt;
                      &lt;xs:element name="ThirdPartyName"         type="xs:string" /&gt;
                      &lt;xs:element name="ThirdPartyAddressLine1" type="xs:string" /&gt;
                      &lt;xs:element name="ThirdPartyAddressLine2" type="xs:string" /&gt;
                      &lt;xs:element name="ThirdPartyAddressLine3" type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ThirdPartyAddressLine4" type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ThirdPartyPostCode"     type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ThirdPartyTelNo"        type="xs:string" minOccurs="0" /&gt;
                      &lt;xs:element name="ThirdPartyEmail"        type="xs:string" minOccurs="0" /&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
                &lt;xs:element name="ClaimDetails"&gt;
                  &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                      &lt;xs:element name="ItemRequested"&gt;
                        &lt;xs:complexType&gt;
                          &lt;xs:sequence&gt;
                            &lt;xs:element name="ClaimID"          type="xs:int" /&gt;
                            &lt;xs:element name="AssistanceType"   type="xs:string" /&gt;
                            &lt;xs:element name="GoodsType"        type="xs:string" /&gt;
                            &lt;xs:element name="AmountRequested"  type="xs:decimal" minOccurs="0" /&gt;
                            &lt;xs:element name="ItemQuantity"     type="xs:int" /&gt;
                          &lt;/xs:sequence&gt;
                        &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                      &lt;xs:element name="AwardDetail"&gt;
                        &lt;xs:complexType&gt;
                          &lt;xs:sequence&gt;
                            &lt;xs:element name="AwardDate"        type="xs:date" /&gt;
                            &lt;xs:element name="AwardValue"       type="xs:decimal" /&gt;
                            &lt;xs:element name="QuantityAwarded"  type="xs:int" /&gt;
                            &lt;xs:element name="TotalAwardValue"  type="xs:decimal" /&gt;
                            &lt;xs:element name="PaymentType"      type="xs:string" /&gt;
                            &lt;xs:element name="Recoverable"      type="xs:boolean" /&gt;
                            &lt;xs:element name="Reference1Name"   type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference1Value"  type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference2Name"   type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference2Value"  type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference3Name"   type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference3Value"  type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference4Name"   type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference4Value"  type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference5Name"   type="xs:string" minOccurs="0" /&gt;
                            &lt;xs:element name="Reference5Value"  type="xs:string" minOccurs="0" /&gt;
                          &lt;/xs:sequence&gt;
                        &lt;/xs:complexType&gt;
                      &lt;/xs:element&gt;
                    &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
                &lt;/xs:element&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
          &lt;xs:element name="Trailer"&gt;
            &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                &lt;xs:element name="NoOfRecords"        type="xs:int" /&gt;
                &lt;xs:element name="TotalOfAwardValues" type="xs:decimal" /&gt;
              &lt;/xs:sequence&gt;
            &lt;/xs:complexType&gt;
          &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>One of the XML files is below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Awards&gt;
    &lt;Header&gt;
      &lt;FinAssType&gt;XXX&lt;/FinAssType&gt;
      &lt;FileType&gt;Awards&lt;/FileType&gt;
      &lt;ExtractDateTime&gt;2013-04-03T16:50:15.483&lt;/ExtractDateTime&gt;
      &lt;LACode /&gt;
      &lt;OrganisationName&gt;Org&lt;/OrganisationName&gt;
      &lt;SupplierDetails&gt;
        &lt;SupplierID&gt;3&lt;/SupplierID&gt;
        &lt;SupplierName&gt;xxx&lt;/SupplierName&gt;
        &lt;SupplierAddress&gt;xxx&lt;/SupplierAddress&gt;
      &lt;/SupplierDetails&gt;
    &lt;/Header&gt;
    &lt;AwardRecords&gt;
      &lt;CaseIdentification&gt;
        &lt;CaseReference&gt;XXX1156&lt;/CaseReference&gt;
        &lt;DateOfApplication&gt;2013-03-30&lt;/DateOfApplication&gt;
        &lt;ReasonForApplication&gt;Moving Home/Resettlement&lt;/ReasonForApplication&gt;
      &lt;/CaseIdentification&gt;
      &lt;ApplicantDetails&gt;
        &lt;ApplicantTitle&gt;Mr&lt;/ApplicantTitle&gt;
        &lt;ApplicantForename&gt;test&lt;/ApplicantForename&gt;
        &lt;ApplicantSurname&gt;test&lt;/ApplicantSurname&gt;
        &lt;ApplicantNINO&gt;XX999999X&lt;/ApplicantNINO&gt;
        &lt;DateOfBirth&gt;1984-03-03&lt;/DateOfBirth&gt;
        &lt;ApplicantAddress1&gt;12&lt;/ApplicantAddress1&gt;
        &lt;ApplicantAddress2&gt;1&lt;/ApplicantAddress2&gt;
        &lt;ApplicantAddress3&gt;3&lt;/ApplicantAddress3&gt;
        &lt;ApplicantAddress4&gt;3&lt;/ApplicantAddress4&gt;
        &lt;ApplicantPostcode&gt;m16 7ha&lt;/ApplicantPostcode&gt;
        &lt;ApplicantTelNo&gt;01611234567&lt;/ApplicantTelNo&gt;
        &lt;ApplicantEmail&gt;test@test.com&lt;/ApplicantEmail&gt;
        &lt;DateMovedIn&gt;1991-11-28&lt;/DateMovedIn&gt;
      &lt;/ApplicantDetails&gt;
      &lt;ClaimDetails&gt;
        &lt;Claim&gt;
          &lt;ItemRequested&gt;
            &lt;ClaimID&gt;20&lt;/ClaimID&gt;
            &lt;AssistanceType&gt;Beds and mattresses&lt;/AssistanceType&gt;
            &lt;GoodsType&gt;Double bed (standard mattress)&lt;/GoodsType&gt;
            &lt;ItemQuantity&gt;1&lt;/ItemQuantity&gt;
          &lt;/ItemRequested&gt;
          &lt;AwardDetail&gt;
            &lt;AwardDate&gt;2013-03-30T11:33:27.307&lt;/AwardDate&gt;
            &lt;AwardValue&gt;134.03&lt;/AwardValue&gt;
            &lt;QuantityAwarded&gt;1&lt;/QuantityAwarded&gt;
            &lt;TotalAwardValue&gt;134.03&lt;/TotalAwardValue&gt;
            &lt;PaymentType&gt;Delivery to customer&lt;/PaymentType&gt;
            &lt;Recoverable&gt;0&lt;/Recoverable&gt;
            &lt;Reference1Name&gt;Delivery/accessibility info&lt;/Reference1Name&gt;
            &lt;Reference1Value /&gt;
            &lt;Reference2Name&gt;Notes&lt;/Reference2Name&gt;
            &lt;Reference2Value /&gt;
            &lt;Reference3Value /&gt;
            &lt;Reference4Value /&gt;
            &lt;Reference5Value /&gt;
          &lt;/AwardDetail&gt;
        &lt;/Claim&gt;
      &lt;/ClaimDetails&gt;
    &lt;/AwardRecords&gt;
    &lt;AwardRecords&gt;
      &lt;CaseIdentification&gt;
        &lt;CaseReference&gt;XXX1483&lt;/CaseReference&gt;
        &lt;DateOfApplication&gt;2013-04-03&lt;/DateOfApplication&gt;
        &lt;ReasonForApplication&gt;xxx&lt;/ReasonForApplication&gt;
      &lt;/CaseIdentification&gt;
      &lt;ApplicantDetails&gt;
        &lt;ApplicantTitle&gt;Ms&lt;/ApplicantTitle&gt;
        &lt;ApplicantForename&gt;xxx&lt;/ApplicantForename&gt;
        &lt;ApplicantSurname&gt;xxx&lt;/ApplicantSurname&gt;
        &lt;ApplicantNINO&gt;xxx&lt;/ApplicantNINO&gt;
        &lt;DateOfBirth&gt;1959-04-25&lt;/DateOfBirth&gt;
        &lt;ApplicantAddress1&gt;xxx&lt;/ApplicantAddress1&gt;
        &lt;ApplicantAddress2&gt;xxx&lt;/ApplicantAddress2&gt;
        &lt;ApplicantAddress3&gt;xxx&lt;/ApplicantAddress3&gt;
        &lt;ApplicantAddress4 /&gt;
        &lt;ApplicantPostcode&gt;xxx&lt;/ApplicantPostcode&gt;
        &lt;ApplicantTelNo&gt;xxx&lt;/ApplicantTelNo&gt;
        &lt;ApplicantEmail /&gt;
        &lt;DateMovedIn&gt;2013-04-02&lt;/DateMovedIn&gt;
      &lt;/ApplicantDetails&gt;
      &lt;ClaimDetails&gt;
        &lt;Claim&gt;
          &lt;ItemRequested&gt;
            &lt;ClaimID&gt;88&lt;/ClaimID&gt;
            &lt;AssistanceType&gt;xxx&lt;/AssistanceType&gt;
            &lt;GoodsType&gt;xxx&lt;/GoodsType&gt;
            &lt;ItemQuantity&gt;1&lt;/ItemQuantity&gt;
          &lt;/ItemRequested&gt;
          &lt;AwardDetail&gt;
            &lt;AwardDate&gt;2013-04-03T15:54:55.100&lt;/AwardDate&gt;
            &lt;AwardValue&gt;134.03&lt;/AwardValue&gt;
            &lt;QuantityAwarded&gt;1&lt;/QuantityAwarded&gt;
            &lt;TotalAwardValue&gt;134.03&lt;/TotalAwardValue&gt;
            &lt;PaymentType&gt;Delivery to customer&lt;/PaymentType&gt;
            &lt;Recoverable&gt;0&lt;/Recoverable&gt;
            &lt;Reference1Name&gt;xxx&lt;/Reference1Name&gt;
            &lt;Reference1Value /&gt;
            &lt;Reference2Name&gt;Notes&lt;/Reference2Name&gt;
            &lt;Reference2Value&gt;xxx&lt;/Reference2Value&gt;
            &lt;Reference3Value /&gt;
            &lt;Reference4Value /&gt;
            &lt;Reference5Value /&gt;
          &lt;/AwardDetail&gt;
        &lt;/Claim&gt;
      &lt;/ClaimDetails&gt;
    &lt;/AwardRecords&gt;
    &lt;Trailer&gt;
      &lt;NoOfRecords&gt;2&lt;/NoOfRecords&gt;
      &lt;TotalOfAwardValues&gt;268&lt;/TotalOfAwardValues&gt;
    &lt;/Trailer&gt;
  &lt;/Awards&gt;
  </code></pre>
  
  <p>Also, after I have verified using the schema, I am going to need a further loop to iterate through the files and store the contents of the 'Awards/Header/SupplierDetails/SupplierName' node - how can I do this?</p>
  
  <p>Thanks.</p>