SOLVED

XPath and name space

Copper 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
best response confirmed by fdlsmg-ladnsgamgdn1390 (Copper Contributor)
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

1 best response

Accepted Solutions
best response confirmed by fdlsmg-ladnsgamgdn1390 (Copper Contributor)
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

View solution in original post