
"object required" error...
documentElement.selectNodes() returns a collection (a nodeList), not an array. Use the length
property of the nodeList, not UBound() or just walk it with a For Each...Next loop.
Here's a .wsf example with the XML embedded in a <resource> element...
<?xml version="1.0"?>
<job>
<script language="vbscript" >
Dim oXml, oNodes, oNode, N
Set oXml = CreateObject ("Microsoft.XMLDOM")
With oXml
.Async = False
.LoadXML getResource("myXML")
End With
msgbox oXml.xml
set oNodes = oXml.documentElement.selectNodes("Project")
'===
' indexing via item method...
'===
For N = 0 to oNodes.length -1
Set oNode = oNodes.item(N).SelectSingleNode("ID")
MsgBox oNode.Text
If oNode.Text = "2" Then
MsgBox "Yahoo!!"
End If
Next
'===
' walking with For Each...
'===
For Each oProject in oNodes
Set oNode = oProject.SelectSingleNode("ID")
MsgBox oNode.Text
If oNode.Text = "2" Then
MsgBox "Yahoo!!"
End If
Next
Set oNodes = Nothing
Set oXml = Nothing
</script>
<resource id="myXML">
<![CDATA[
<Projects>
<Project>
<ID>1</ID>
</Project>
<Project>
<ID>2</ID>
</Project>
</Projects>
]]>
</resource>
</job>
--
Michael Harris
Microsoft.MVP.Scripting
--
Quote:
> Learning vbscript. Getting error I don't understand. I get
> the "object required" error whenever I try to use an xmlnode's text or
> xml attributes. Here's a reduced code snippet...
> Dim nodeList,curNode,idNode,iItem
> Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM")
> XMLDoc.Async = False
> XMLDoc.load(Server.MapPath("xml\Intotal Projects.xml"))
> Set nodeList = XMLDoc.documentElement.selectNodes("Project")
> iItem = 0
> for each curNode in nodeList
> Set idNode = curNode.selectSingleNode("ID")
> Response.Write(idNode.text) 'error here
> if (idNode.text = "2") then 'same error here
> Response.Write("Yahoo!!")
> end if
> iItem = iItem+1
> next
> Thanx for any help!
> Sent via Deja.com http://www.deja.com/
> Before you buy.