Dynamic namespace prefix issue in xpath of the xml tag - MSXML


  • Hi,

    I am trying to access my xml using "MSXML2' dom object  using vb scripting.

    Set oMessageDoc = CreateObject( "MSXML2.DOMDocument" )

    however I have dynamic namespace prefix for same tag in each xml file. Example provided below

    Tag-> <ns1:Addr><ns1:Street>abc street </ns1:Street> </ns1:Addr>

    same tag is referred in another xml as, <ns2:Addr><ns2:Street>abc street </ns2:Street> </ns2:Addr>


    I am trying to access xml tag as "ns1:Addr/ns1:Street" and  "ns2:Addr/ns2:Street"  though both refers same tag (ns1, ns2 are same namespace URI)

    is it possible to access xmltag's xpath without prefix, as like "Addr/Street"?

    Wednesday, May 08, 2013 9:48 PM

All replies

  • First of all, with "MSXML2.DOMDocument" you are getting MSXML 3.0 for which the selection language has to be explicitly set to XPath with e.g.

      oMessageDoc.setProperty "SelectionLanguage", "XPath"

    As for using "Addr/Street", no, with XPath 1.0 which is all Microsoft supports that always selects elements of those names in no namespace.

    But of course if the elements are in the same namespace then all you need is

      oMessageDoc.setProperty "SelectionNamespaces", "xmlns:ns1=''"

    (where you put the namespace URI of the input XML in the place of and then in your code you can select




    MVP (XML, Data Platform Development) 2005/04 - 2013/03 My blog

    Thursday, May 09, 2013 10:07 AM