saturation
asked on
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("Micro soft.XMLDO M")
xmlDocSet.load(sRequest)
Response.Write xmlDocSet.documentElement. childNodes (0).attrib utes.getNa medItem("L ISTING").n odeValue
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
Dim xmlDocSet
Set xmlDocSet = Server.CreateObject("Micro
xmlDocSet.load(sRequest)
Response.Write xmlDocSet.documentElement.
ASKER
I got
Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'
Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'
where is the xml you are trying to load. If the xml is invalid, then you will get the error you just described.
ASKER
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>
<?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>
ASKER
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>
<?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>
ASKER
Ignore the hyperlink. The XML is well-formed.
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
ASKER
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?
msxml3.dll error '80004005'
Attempt to modify a read-only node.
The line of code that errors is
xmlDocSet.setProperty "SelectionLanguage", "XPath"
Thoughts?
are you loading a local file? If so, are you specifying the full path to the file?
ASKER
I just load the XML into a variable on the page. Should it be loaded into a local file?
>>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("Tit le").text
Your xml node name is in upper case, so it should be:
node.selectSingleNode("TIT LE").text
I was just trying to make sure the data is loading fine. Can you post your code?
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("Tit
Your xml node name is in upper case, so it should be:
node.selectSingleNode("TIT
I was just trying to make sure the data is loading fine. Can you post your code?
ASKER
Dim xmlDocSet
Set xmlDocSet=Server.CreateObj ect("MSXML 2.DOMDocum ent")
xmlDocSet.load sRequest
xmlDocSet.setProperty "SelectionLanguage", "XPath"
Set nodes = xmlDocSet.documentElement. selectNode s("//RESUL TS/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("RAN K").text )
Response.write( "Title" & node.selectSingleNode("TIT LE").text )
Next
Set nodes = Nothing
Set xmlDocSet = Nothing
Set xmlDocSet=Server.CreateObj
xmlDocSet.load sRequest
xmlDocSet.setProperty "SelectionLanguage", "XPath"
Set nodes = xmlDocSet.documentElement.
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("RAN
Response.write( "Title" & node.selectSingleNode("TIT
Next
Set nodes = Nothing
Set xmlDocSet = Nothing
>>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)
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)
ASKER
If I set to loadXML instead of load, I get
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
Set nodes = xmlDocSet.documentElement. selectNode s("//RESUL TS/LISTING ")
is the line of the error.
Microsoft VBScript runtime error '800a01a8'
Object required: '[object]'
Set nodes = xmlDocSet.documentElement.
is the line of the error.
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
%>
ASKER
So bizarre, back to
Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'
on line
Set nodes = xmlDocSet.documentElement. selectNode s("//RESUL TS/LISTING ")
I double-checked and the xml is fine.
Microsoft VBScript runtime error '800a01a8'
Object required: 'documentElement'
on line
Set nodes = xmlDocSet.documentElement.
I double-checked and the xml is fine.
what if you change:
MSXML2.DOMDocument
to:
Microsoft.XMLDOM
MSXML2.DOMDocument
to:
Microsoft.XMLDOM
ASKER
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.CreateObj ect("MSXML 2.DOMDocum ent")
Set xmlDocSet=Server.CreateObj ect("Micro soft.XMLDO M")
xmlDocSet.loadXML "test1.xml"
If Err.Number = 0 Then
xmlDocSet.setProperty "SelectionLanguage", "XPath"
Set nodes = xmlDocSet.documentElement. selectNode s("//RESUL TS/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("RAN K").text )
' Response.write( "Title" & node.selectSingleNode("TIT LE").text )
Next
Set nodes = Nothing
Else
Response.Write Er.number & "yes " & Err.Description
End If
Set xmlDocSet = Nothing
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.CreateObj
Set xmlDocSet=Server.CreateObj
xmlDocSet.loadXML "test1.xml"
If Err.Number = 0 Then
xmlDocSet.setProperty "SelectionLanguage", "XPath"
Set nodes = xmlDocSet.documentElement.
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("RAN
' Response.write( "Title" & node.selectSingleNode("TIT
Next
Set nodes = Nothing
Else
Response.Write Er.number & "yes " & Err.Description
End If
Set xmlDocSet = Nothing
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" )
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"
ASKER
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?
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("LIN K").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.selectSingl eNode("LIN K").text) )
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("LIN
you will need to pass it to the decoding function first and print the result of the decoding function:
Response.write( "Rank" & URLDecode(node.selectSingl
ASKER
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. selectNode s("//RESUL TS/LISTING ")
Check the page again and you'll see what I mean...I just put the code back.
Set nodes = xmlDocSet.documentElement.
Check the page again and you'll see what I mean...I just put the code back.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
Set xmlDocSet=Server.CreateObj
xmlDocSet.load sRequest
If Err.Number<>0 Then
Response.Write "Error ocurred:" & Err.description
Else
'do your processing here
Response.Write xmlDocSet.documentElement.
End If
Reference:
https://www.experts-exchange.com/questions/20537562/XML-Dom-GetAttribute-in-ASP.html