-
Xml Dom
i'm currently learning all about the great wonders of the xml dom... but why the hell won't this code work?!?!
Code:
<%
Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objXMLDoc.Load("note.xml")
objXMLDoc.async=false
Response.Write objXMLDoc.documentElement.nodeName
For Each objNode in objXMLDoc.documentElement.childNodes
' do whatever
Next
Set objXMLDoc = Nothing
%>
i always get an "object required" error...
thanks in advance!
-
Shouldn't you set async to false before you load it? Otherwise you could be trying to access its elements before it's fully loaded.
-
thanks, josh... unfortunately, that wasn't the problem... i'm still getting the "object required" error... this is driving me nuts at this point... i know it's probably simple to resolve, but those usually present the biggest headaches...
-
What line is the error on?
-
well... maybe i've figured out why the root element isn't found... i altered the code to read:
Code:
<%
Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objXMLDoc.async=false
If objXMLDoc.Load("note.xml") Then
Response.Write "XML Document Loaded."
Else
Response.Write "XML Not Loaded."
End If
Set objRoot = objXMLDoc.documentElement
'strFrom = objRoot.selectSingleNode("from").text
'For Each objNode in objRoot
' do whatever
'Next
Set objXMLDoc = Nothing
%>
this is the source of the file note.xml:
Code:
<?xml version="1.0" ?>
<note>
<to>You</to>
<from>Me</from>
<message>This is a test.</message>
</note>
the result is, of course, 'XML Not Loaded'... what a pain... please help... at this point, i'd rather stab myself in the leg than deal with the xml dom...
-
How about if you change this:
Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
to this
Set objXMLDoc = Server.CreateObject("MSXML.DOMDocument")
or this
Set objXMLDoc = Server.CreateObject("MSXML2.DOMDocument")
Will it work any better?
-
thanks again, josh... but it is still returning "XML Not Loaded."... i have no clue at this point... now where is that java book?...