"object required" error... 
Author Message
 "object required" error...

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.*-*-*.com/
Before you buy.



Tue, 15 Apr 2003 08:26:07 GMT  
 "object required" error...

I think selectNodes returns an Array not a collection.

Dim oXml, oNodes, oNode, N
Set oXml = Server.CreateObject ("Microsoft.XMLDOM")
With oXml
 .Async = False
 .Load (Server.MapPath ("xml/intotal projects.xml"))
End With
oNodes = oXml.DocumentElement.SelectNodes ("Project")
For N=0 To UBound (oNodes)
 Set oNode = oNodes(N).SelectSingleNode ("ID")
 Response.Write (oNode.Text)
 If oNode.Text = "2" Then
  Response.Write ("Yahoo!!")
 End If
Next
Set oNodes = Nothing
Set oXml = Nothing
<

Difficult to know for sure without knowing the structure of your XML
document.

--
Dominic

Read The Docs? http://msdn.microsoft.com/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.



Tue, 15 Apr 2003 19:16:53 GMT  
 "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.



Wed, 16 Apr 2003 03:26:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. "Object Required" error

2. "Object Required" error

3. "Object Required" error

4. Help: "Object Required" - error 424

5. "Object required" error message

6. VBScript "Object Required WScript" Error

7. Error, Object Required "Wscript"

8. help: error 424 "Object Required"

9. detecting "object required" or null object

10. detecting "object required" or null object

11. window.open - "Object required"

12. Object Required "txtPrice"

 

 
Powered by phpBB® Forum Software