我的问题类似于here所描述的内容。但它不适用于Excel-VBA。
答案 0 :(得分:1)
您会发现实际上text属性会解析<![CDATA[]]>
的CDATA转义字符。所以实际上代码非常简单。这是一个例子。
Sub Test()
Dim sXml As String
sXml = "<Root><SomeData>foo</SomeData>" & _
"<SomeCDATA><![CDATA[<img src=""http://l.yimg.com/a/i/us/we/52/26.gif""/>]]>" & _
"</SomeCDATA></Root>"
'Tools->References->Microsoft Xml v.60
Dim dom As MSXML2.DOMDocument60
Set dom = New MSXML2.DOMDocument60
dom.LoadXML sXml
Debug.Assert dom.parseError = 0
Dim xmlSomeCData As MSXML2.IXMLDOMElement
Set xmlSomeCData = dom.SelectSingleNode("Root/SomeCDATA")
Debug.Print xmlSomeCData.Text
'* or your suggestion :)
Dim xmlSomeCDataSection As MSXML2.IXMLDOMCDATASection
Set xmlSomeCDataSection = dom.SelectSingleNode("Root/SomeCDATA/text()")
Debug.Print xmlSomeCDataSection.Text
End Sub
以上代码输出<img src="http://l.yimg.com/a/i/us/we/52/26.gif"/>