我有一個XPath查詢//*[local-name()='Home Query Data']
,測試here。 現在我必須執行此XPath才能返回<Home Query Data> --- </Home Query Data>
標記中的所有文本。XML DOM在標籤內獲取文本
我應該用什麼DOM選擇器從標籤中選擇整個文本? 像:objMSXML.selectNodes(XPath)
編輯
我使用的VBScript我的編程。我的代碼如下:
Sub ReadXml(FileName)
Dim nodeinfo (4)
Dim sXPath
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileObj = fso.GetFile(FileName)
objMSXML.async = True
objMSXML.load FileName
If 0 = objMSXML.parseError Then
sXPath = "//*[local-name()='Home Query Data']"
End If
Dim querySubject : Set querySubject = objMSXML.selectSingleNode(sXPath)
If querySubject Is Nothing Then
MsgBox sXPath, "failed" ** Error type mismatch [string "failed"]**
Else
For Each node In objMSXML.selectNodes(sXPath)
MsgBox node
Next
End If
End Sub
我抄它的一些其他職位,無法弄清楚如何將XML標籤內返回全部文本。
我在這部分的問題:
Dim querySubject : Set querySubject = objMSXML.selectSingleNode(sXPath)
If querySubject Is Nothing Then
MsgBox sXPath, "failed"
Else
For Each node In objMSXML.selectNodes(sXPath)
MsgBox node
Next
End If
EDIT2
我的工作XML是這樣的:
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name locale="en">Stage Query Data</name>
<price>$5.95</price>
<description>Our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<drink>
<name locale="en">Home Query Data</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</drink>
<mix>
<name locale="en">Report Query Data</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</mix>
</breakfast_menu>
我需要標籤<drink>
名稱爲內捕獲文本Home Query Data
。
<name locale="en">Home Query Data</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
目前我在MSGBOX sXPath饒人, 「失敗」 **錯誤類型不匹配[字符串 「失敗」] **
你試過'node.text'? https://msdn.microsoft.com/en-us/library/ms763798.aspx –
xpath的問題。它表示類型不匹配sxpath .... –
顯示完整的錯誤消息。還顯示您的XML數據的代表(工作)樣本。 –