HI, I have this asp classic app and I am trying to retrieve a single node, but I keep getting an Object Required error. The selectNodeBytags works but returns a node list I just want a single node.
This errors with "Object Required"
<%
option explicit
Dim xmlDoc
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
Dim node
If xmlDoc.load(Server.MapPath("vocabulary.xml")) Then
xmlDoc.setProperty "SelectionLanguage", "XPath"
set node = xmlDoc.selectSingleNode("Word[@type='noun']")
Response.write node.text
end if
%>
This works using getElementsByTagName
<%
option explicit
Dim xmlDoc
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = False
Dim node
If xmlDoc.load(Server.MapPath("vocabulary.xml")) Then
xmlDoc.setProperty "SelectionLanguage", "XPath"
' Grabs the elements in each "word" element
Dim nodelist
Set nodelist = xmlDoc.getElementsByTagName("Word")
for each node in nodelist
Response.write(node.nodeName) & "<br />" 'Returns parent node name
Response.write(node.text) & "<br />"
next
end if
%>
xml file I am using
<?xml version="1.0" encoding="utf-8" ?>
<Vocabulary>
<Word type="noun" level="1">
<English>cat</English>
<Spanish>gato</Spanish>
</Word>
<Word type="verb" level="1">
<English>speak</English>
<Spanish>hablar</Spanish>
</Word>
<Word type="adj" level="1">
<English>big</English>
<Spanish>grande</Spanish>
</Word>
</Vocabulary>