Click to See Complete Forum and Search --> : Error with XML DOM object


graatz
09-28-2005, 02:54 PM
So I'm finally trying to learn how to use xml and asp but am having an odd sort of a problem (well, it's odd to me, but I'm hoping it's something dumb I'm missing). I've stripped my problem down to the basics as such:

here an .asp file:
<% if 1=2 then %>

<%
Function getname(strURL)

set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = "false"
xmlDoc.load(strURL)

getname = xmlDoc.documentElement.getElementsByTagName("child").item(0).getAttribute("name")

End Function
%>
<html><head><title>test</title></head><body><%=getname("test.xml")%><br /><%=getname("test2.xml")%></body></html>

<% else %>
<html><head><title>test</title>

<script type="text/vbscript">
Sub getname(strURL)

set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = "false"
xmlDoc.load(strURL)

MsgBox(xmlDoc.documentElement.getElementsByTagName("child").item(0).getAttribute("name"))
End Sub
</script>

</head><body><input type="button" onclick="getname('test.xml')"><br><input type="button" onclick="getname('test2.xml')"></body></html>

<% end if %>

Now the way it's set up (with 1=2 at the head) it runs fine.. i get two buttons, clicking the top one gives me one name, and clicking the bottom gets me another... this is done client-side... now i want to do the same thing server-side (as in the example, display the names rather then call them up in a message box) so change 1=1 for what seems to me the equivalent server-side vbscript ... but when i try to pull that, i get the error message:

Microsoft VBScript runtime (0x800A01A8)
Object required: 'xmlDoc.documentElement'
/<name>.asp, line 10

I've been stuck on this more than I'd like to be, so I'm hoping someone can help out... below are the two .xml files:

test.xml:
<?xml version="1.0" encoding="utf-8" ?>
<parent>
<child name="Sally"></child>
</parent>
test2.xml
<?xml version="1.0" encoding="utf-8" ?>
<parent>
<child name="Bobby"></child>
</parent>

This is an over-simplification of the master plan, so I'm looking for an answer moreso than "set up the whole thing differently" .. I specifically would like to parse out xml from multiple pages on the one ASP page, and need to be able to navigate those pages server-side, or else the tedium will drive me crazy :p

russell_g_1
09-28-2005, 04:26 PM
if you're using asp then why are you doing the xml processing on the client-side? it would be better to do this kind of stuff on the server-side like the example below.

<html>
<body>

test.xml = <%=getName("test.xml")%>
<br>
test2.xml = <%=getName("test2.xml")%>

</body>
</html>


<%


function getName(xmldocpath)

on error resume next

getName = ""

set xmldoc = CreateObject("MSXML2.DOMDocument.4.0")

xmldoc.async = false
xmlDoc.resolveExternals = False
xmldoc.load server.mappath(xmldocpath)

if xmldoc.parseerror = 0 then

getName = xmlDoc.selectSingleNode("/parent/child/@name").value

end if

end function



%>

graatz
09-29-2005, 07:24 AM
hmm... i'm thinking my problem might be that the XML I'm requesting is being dynamically generated through a different ASP page... I'm not sure why, then, at client-side the script is still able to extract the data but it fails at server-side... i'll see if i can set up an example...