How to ignore a XML namespace

后端 未结 1 1788
盖世英雄少女心
盖世英雄少女心 2021-01-25 14:42

I have an XML file and this XML file has namespaces declared



        
1条回答
  •  粉色の甜心
    2021-01-25 15:27

    This worked for me (after some amount of head-scratching)

    Sub Tester()
    
        Const XML As String = "" & _
        "" & _
        "   Testing" & _
        ""
    
        Dim xmlDom As New MSXML2.DOMDocument60
        Dim nodeList As MSXML2.IXMLDOMNodeList
        Dim iNode As MSXML2.IXMLDOMNode
    
        With xmlDom
            .async = False
            .validateOnParse = True
            .LoadXML XML
            .setProperty "SelectionLanguage", "XPath"
    
            'set the default namespace and give it a prefix (e.g.) "xx"
            .setProperty "SelectionNamespaces", _
                         "xmlns:xx='urn:crystal-reports:schemas:report-detail'"
    
            'use the same default prefix in your XPath
            Set nodeList = .SelectNodes("//xx:Test")
    
        End With
    
        Debug.Print nodeList.Length
        For Each iNode In nodeList
            Debug.Print iNode.XML
        Next iNode
    
    End Sub
    

    0 讨论(0)
提交回复
热议问题