Forum Discussion

fdlsmg-ladnsgamgdn1390's avatar
fdlsmg-ladnsgamgdn1390
Copper Contributor
Jun 10, 2019
Solved

XPath and name space

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 incorpo...
  • kinuasa's avatar
    Jun 12, 2019

    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-default-namespace

     

    Best regards,
    kinuasa

Resources