SOLVED
Home

XPath and name space

%3CLINGO-SUB%20id%3D%22lingo-sub-680697%22%20slang%3D%22en-US%22%3EXPath%20and%20name%20space%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-680697%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20everyone.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20get%20the%26nbsp%3B%3CIDENTIFIER%3E%20element%20from%20the%20XML%20below%20using%20xpath%20and%20xmlDoc.SelectNodes(%22%5C%5CIdentifier%22)%20without%20luck.%20It%20seems%20that%20the%20%22n1%3A%22%20qualifier%20has%20to%20be%20incorporated%20but%20I%20cannot%20see%20how.%20Any%20suggestions%3F%3C%2FIDENTIFIER%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3EB.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEPCISDOCUMENT%20creationdate%3D%22%26quot%3B2019-06-10T16%3A23%3A07Z%26quot%3B%22%20schemaversion%3D%22%26quot%3B1.1%26quot%3B%22%20epcis%3D%22%26quot%3Burn%3Aepcglobal%3Aepcis%3Axsd%3A1%26quot%3B%22%20gs1ushc%3D%22%26quot%3B%26lt%3BA%22%20href%3D%22http%3A%2F%2Fepcis.gs1us.org%2Fhc%2Fns%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%22%3E%3CA%20href%3D%22http%3A%2F%2Fepcis.gs1us.org%2Fhc%2Fns%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fepcis.gs1us.org%2Fhc%2Fns%3C%2FA%3E%22%20xmlns%3Asbdh%3D%22%3CA%20href%3D%22http%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%3C%2FA%3E%22%26gt%3B%3CBR%20%2F%3E%3CEPCISHEADER%3E%3CBR%20%2F%3E%3CSTANDARDBUSINESSDOCUMENTHEADER%20n1%3D%22%26quot%3B%26lt%3BA%22%20href%3D%22http%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%22%3E%3CA%20href%3D%22http%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%3C%2FA%3E%22%26gt%3B%3CBR%20%2F%3E%3CHEADERVERSION%3E1.0%3C%2FHEADERVERSION%3E%3CBR%20%2F%3E%3CSENDER%3E%3CBR%20%2F%3E%3CIDENTIFIER%20authority%3D%22%26quot%3BGLN%26quot%3B%22%3E97823048243%3C%2FIDENTIFIER%3E%3CBR%20%2F%3E...%3C%2FSENDER%3E%3C%2FSTANDARDBUSINESSDOCUMENTHEADER%3E%3C%2FEPCISHEADER%3E%3C%2FEPCISDOCUMENT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-680697%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-685183%22%20slang%3D%22en-US%22%3ERe%3A%20XPath%20and%20name%20space%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-685183%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F357543%22%20target%3D%22_blank%22%3E%40fdlsmg-ladnsgamgdn1390%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20recommend%20using%20setProperty%20Method.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPublic%20Sub%20Sample()%3CBR%20%2F%3E%26nbsp%3B%20With%20CreateObject(%22MSXML2.DOMDocument%22)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.async%20%3D%20False%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20If%20.Load(%22C%3A%5CTest%5CTest.xml%22)%20Then%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20.SetProperty%20%22SelectionNamespaces%22%2C%20%22xmlns%3An1%3D'%3CA%20href%3D%22http%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.unece.org%2Fcefact%2Fnamespaces%2FStandardBusinessDocumentHeader%3C%2FA%3E'%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Debug.Print%20.SelectNodes(%22%2F%2Fn1%3AIdentifier%22).Item(0).XML%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20End%20If%3CBR%20%2F%3E%26nbsp%3B%20End%20With%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eref.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F288147%2Fhow-to-use-xpath-to-query-against-a-user-defined-default-namespace%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Fhelp%2F288147%2Fhow-to-use-xpath-to-query-against-a-user-defined-default-namespace%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%2C%3CBR%20%2F%3Ekinuasa%3C%2FP%3E%3C%2FLINGO-BODY%3E
fdlsmg-ladnsgamgdn1390
New Contributor

Hi everyone.

 

I am trying to get the <n1:Identifier> element from the XML below using xpath and xmlDoc.SelectNodes("\\Identifier") without luck. It seems that the "n1:" qualifier has to be incorporated but I cannot see how. Any suggestions?

 

Thanks

B.

 

<epcis:EPCISDocument creationDate="2019-06-10T16:23:07Z" schemaVersion="1.1" xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:gs1ushc="http://epcis.gs1us.org/hc/ns" xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<EPCISHeader>
<n1:StandardBusinessDocumentHeader xmlns:n1="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">
<n1:HeaderVersion>1.0</n1:HeaderVersion>
<n1:Sender>
<n1:Identifier Authority="GLN">97823048243</n1:Identifier>
...

1 Reply
Solution

@fdlsmg-ladnsgamgdn1390 

 

Hi,

I recommend using setProperty Method.

 

Public Sub Sample()
  With CreateObject("MSXML2.DOMDocument")
    .async = False
    If .Load("C:\Test\Test.xml") Then
      .SetProperty "SelectionNamespaces", "xmlns:n1='http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader'"
      Debug.Print .SelectNodes("//n1:Identifier").Item(0).XML
    End If
  End With
End Sub

 

ref.
https://support.microsoft.com/en-us/help/288147/how-to-use-xpath-to-query-against-a-user-defined-def...

 

Best regards,
kinuasa

Related Conversations
Extentions Synchronization
Deleted in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
36 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies