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
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