0
我想通過VBScript訪問一個XML元素,它不工作,可能是因爲命名空間。我試過很多不同的方式,但我總是得到錯誤 「VBScript運行時錯誤:所需的對象」如何訪問以下XML元素或使用VBScript刪除命名空間?
XML:
<?xml version="1.0" encoding="utf-8"?>
<AssetInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://unitedwholesale.com.au/webservices/external/">
<ID>66399</ID>
<AssetLife>3.00</AssetLife>
<BookValue>0.00</BookValue>
<Tag>IT12345</Tag>
</AssetInfo>
的VBScript:
Dim ns
ns = "http://unitedwholesale.com.au/webservices/external/"
oXMLFile.SetProperty "SelectionNamespaces", "xmlns='" & ns & "'"
Set oNode = oXMLFile.SelectSingleNode("/xmlns:AssetInfo/xmlns:Tag").Text
If Not oNode Is Nothing Then
Response.Write oNode
Else
Response.Write oXMLFile.xml
End If
我也試過:
Set oNode = oXMLFile.SelectSingleNode("//AssetInfo/Tag").Text
和
Set oNode = oXMLFile.SelectSingleNode("/ns:AssetInfo/ns:Tag").Text
......都無濟於事!
如果這將是最簡單的,我會很高興只是拋棄所有的命名空間。
歡迎任何建議!
的可能的複製[發佈使用ASP VBScript的XML /的SelectNodes(http://stackoverflow.com/questions/18987954/issue-with-xml-selectnodes-using-asp-vbscript) 。基本上你需要爲命名空間定義一個符號名(''xmlns' **':ns' **'='「&ns&」'「''),然後在你的XPath表達式中使用這個符號名NS:AssetInfo')。 –
正如一個方面的說法,你使用'oxmlFile.setProperty SelectionLanguage「,」XPath「'?進一步:你的'oNode'並不包含節點對象,而只是一個文本字符串,首先使用'Set oNode = oXMLFile。 SelectSingleNode(「/ xmlns:AssetInfo/xmlns:Tag」)',如果節點不是什麼,使用'txt = oNode.Text'提取文本。注意:我不認爲這會解決您的問題,請參閱@AnsgarWiechers,這些只是我發現的其他問題。 – AutomatedChaos