XMLDOM error parsing in ASP

I get the following error with the code below it on the Response.Write line.  What am I doing wrong?

Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'


Dim xmlDocSet
Set xmlDocSet = Server.CreateObject("Microsoft.XMLDOM")
xmlDocSet.load(sRequest)
Response.Write xmlDocSet.documentElement.childNodes(0).attributes.getNamedItem("LISTING").nodeValue
saturationAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Verify that the xml is loading properly first:

Set xmlDocSet=Server.CreateObject("MSXML2.DOMDocument")
xmlDocSet.load sRequest

If Err.Number<>0 Then
 Response.Write "Error ocurred:" & Err.description
Else
   'do your processing here
   Response.Write xmlDocSet.documentElement.childNodes(0).getAttribute("LISTING")
End If

Reference:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_20537562.html
0
saturationAuthor Commented:
I got

Microsoft VBScript runtime error '800a01a8'

Object required: 'documentElement'
0
hieloCommented:
where is the xml you are trying to load. If the xml is invalid, then you will get the error you just described.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

saturationAuthor Commented:
Here's the XML:

<?xml version="1.0" encoding="UTF-8"?>
<RESULTS>
<LISTING>
<RANK>1</RANK>
<TITLE>My Site</TITLE>
<DESCRIPTION>Search Engine.</DESCRIPTION>
<SITEHOST>MySite</SITEHOST>
<LINK>http://www.mysite.com</LINK>
<ID1>LFPvAffVC0</ID1>
</LISTING>
</RESULTS>
0
saturationAuthor Commented:
Sorry, I meant

<?xml version="1.0" encoding="UTF-8"?>
<RESULTS>
<LISTING>
<RANK>1</RANK>
<TITLE>My Site</TITLE>
<DESCRIPTION>Search Engine.</DESCRIPTION>
<SITEHOST>MySite</SITEHOST>
<LINK>http://www.mysite.com</LINK>
</LISTING>
</RESULTS>
0
saturationAuthor Commented:
Ignore the hyperlink.   The XML is well-formed.
0
hieloCommented:

Set xmlDoc =Server.CreateObject("MSXML2.DOMDocument")

Dim xml

xml="<?xml version=""1.0"" encoding=""UTF-8""?><RESULTS><LISTING><RANK>1</RANK><TITLE>My Site</TITLE><DESCRIPTION>Search Engine.</DESCRIPTION><SITEHOST>MySite</SITEHOST><LINK>http://www.mysite.com</LINK></LISTING></RESULTS>"
xmlDoc.loadXML xml

'if you have the xml in a file, comment out the two lines above and uncomment the 
'two lines that follow instead and provide the right name for your file
'xml="file.xml"
'xmlDoc.load xml

xmlDoc.setProperty "SelectionLanguage", "XPath"
Set nodes = xmlDoc.documentElement.selectNodes("//RESULTS/LISTING")
For Each node in nodes
	'this will give you the content of the LISTING node
	'Response.write( node.text )

	'but if you need to access specific "sub-nodes", then use the selectSingleNode()
	'method on the node object
	Response.write( "Rank" & node.selectSingleNode("RANK").text )
	Response.write( "Title" & node.selectSingleNode("Title").text )
Next
Set nodes = Nothing
Set xmlDoc = Nothing

Open in new window

0
saturationAuthor Commented:
I get

msxml3.dll error '80004005'
Attempt to modify a read-only node.

The line of code that errors is

xmlDocSet.setProperty "SelectionLanguage", "XPath"

Thoughts?
0
hieloCommented:
are you loading a local file? If so, are you specifying the full path to the file?
0
saturationAuthor Commented:
I just load the XML into a variable on the page.   Should it be loaded into a local file?
0
hieloCommented:
>>Should it be loaded into a local file?
It's not necessary to do that. The example I posted loads the data from a variable and it works fine. The only problem with what I posted earlier is:
node.selectSingleNode("Title").text

Your xml node name is in upper case, so it should be:
node.selectSingleNode("TITLE").text

I was just trying to make sure the data is loading fine. Can you post your code?
0
saturationAuthor Commented:
Dim xmlDocSet
Set xmlDocSet=Server.CreateObject("MSXML2.DOMDocument")
xmlDocSet.load sRequest

xmlDocSet.setProperty "SelectionLanguage", "XPath"
Set nodes = xmlDocSet.documentElement.selectNodes("//RESULTS/LISTING")
For Each node in nodes
        'this will give you the content of the LISTING node
        'Response.write( node.text )
 
        'but if you need to access specific "sub-nodes", then use the selectSingleNode()
        'method on the node object
        Response.write( "Rank" & node.selectSingleNode("RANK").text )
        Response.write( "Title" & node.selectSingleNode("TITLE").text )
Next
Set nodes = Nothing
Set xmlDocSet = Nothing

0
hieloCommented:
>>I just load the XML into a variable on the page.
OK, the following contradict the statement above:
xmlDocSet.load sRequest

If sRequest contains the XML "string" (not a URL), then you should be using:
xmlDocSet.loadXML sRequest

If sRequest is the name of your xml file, then provide an absolute path:
xmlDocSet.load Server.Mappath(sRequest)
0
saturationAuthor Commented:
If I set to loadXML instead of load, I get

Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'

Set nodes = xmlDocSet.documentElement.selectNodes("//RESULTS/LISTING")

is the line of the error.
0
hieloCommented:
try this:
<%
Dim sRequest

sRequest="<?xml version=""1.0"" encoding=""UTF-8""?><RESULTS><LISTING><RANK>1</RANK><TITLE>My Site</TITLE><DESCRIPTION>Search Engine.</DESCRIPTION><SITEHOST>MySite</SITEHOST><LINK>http://www.mysite.com</LINK></LISTING></RESULTS>"

Dim xmlDocSet
Set xmlDocSet=Server.CreateObject("MSXML2.DOMDocument")
xmlDocSet.loadXML sRequest

If Err.Number = 0 Then
	xmlDocSet.setProperty "SelectionLanguage", "XPath"
	Set nodes = xmlDocSet.documentElement.selectNodes("//RESULTS/LISTING")
	For Each node in nodes
	        'this will give you the content of the LISTING node
	        'Response.write( node.text )
	 
	        'but if you need to access specific "sub-nodes", then use the selectSingleNode()
	        'method on the node object
	        Response.write( "Rank" & node.selectSingleNode("RANK").text )
	        Response.write( "Title" & node.selectSingleNode("TITLE").text )
	Next
	Set nodes = Nothing
Else
	Response.Write Er.number & " " & Err.Description
End If
Set xmlDocSet = Nothing

%>

Open in new window

0
saturationAuthor Commented:
So bizarre, back to

Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'

on line

Set nodes = xmlDocSet.documentElement.selectNodes("//RESULTS/LISTING")

I double-checked and the xml is fine.
0
hieloCommented:
what if you change:
MSXML2.DOMDocument

to:
Microsoft.XMLDOM
0
saturationAuthor Commented:
No luck...And just to test, I just created a simple file called "test1.xml" with the following, then the asp code is below...If I call test1.xml from a browser, it shows up in teh browser as xml.    Why would I keep getting

Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'





<?xml version="1.0" encoding="UTF-8"?>
<RESULTS>
<LISTING>
<RANK>1</RANK>
</LISTING>
</RESULTS>



'ASP CODE

Dim xmlDocSet
'Set xmlDocSet=Server.CreateObject("MSXML2.DOMDocument")
Set xmlDocSet=Server.CreateObject("Microsoft.XMLDOM")
xmlDocSet.loadXML "test1.xml"
 
If Err.Number = 0 Then
        xmlDocSet.setProperty "SelectionLanguage", "XPath"
        Set nodes = xmlDocSet.documentElement.selectNodes("//RESULTS/LISTING")
        For Each node in nodes
                'this will give you the content of the LISTING node
                'Response.write( node.text )
         
                'but if you need to access specific "sub-nodes", then use the selectSingleNode()
                'method on the node object
                Response.write( "Rank" & node.selectSingleNode("RANK").text )
            '    Response.write( "Title" & node.selectSingleNode("TITLE").text )
        Next
        Set nodes = Nothing
Else
        Response.Write Er.number & "yes " & Err.Description
End If
Set xmlDocSet = Nothing


0
hieloCommented:
OK, let me say it again.
If you are using a FILE, you do NOT use .loadXML(); you use just ".load()"

FILE => .load()
STRING => .loadXML()

So you need
xmlDocSet.load Server.Mappath("test1.xml")

0
saturationAuthor Commented:
Ok, now we're getting places...When I do it with that method, it parses it.   I'm guessing that means that my xml in memory ISN'T, after all, well-formed.   If you look at my xml output to the page from memory, it appears to be fine, so I'm not sure...Can someone take a look at thepetbox.com/test.asp and tell me what might be the problem?
0
hieloCommented:
It's working fine. The reason it looks "cryptic" is because your xml contains encoded urls. You need to decode them.

Unfortunately for you, there a function named Server.urlEncode() BUT there is NO server.urlDecode().

Fortunately for you, someone already did that:
http://flangy.com/dev/asp/urldecode.html

Copy both of those functions to your asp script and then instead of writing the node's text directly:
  Response.write( "Rank" & node.selectSingleNode("LINK").text )

you will need to pass it to the decoding function first and print the result of the decoding function:
  Response.write( "Rank" & URLDecode(node.selectSingleNode("LINK").text)  )
0
saturationAuthor Commented:
But see, it writes it to the page fine when I don't parse through it, which is what I'm doing there...If I use the XMLDOM object...But when I put that code back in and try to just write each node out to the page, it errors on line

        Set nodes = xmlDocSet.documentElement.selectNodes("//RESULTS/LISTING")

Check the page again and you'll see what I mean...I just put the code back.
0
hieloCommented:
I wonder if these components are actually installed in your server.

try:
Set xmlDocSet=Server.CreateObject("Microsoft.XMLDOM")

If xmlDocSet IS Nothing Then
  Response.Write "Unable to create object"
  Response.End
End If

PS: I need to leave for now. I'll check again tomorrow.

Regards,
Hielo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
saturationAuthor Commented:
Wow...I just realized that I was putting the request variable into the load method instead of the actualy XML.   Hielo, you have been a HUGE help!   Thank you so much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.