www.webdeveloper.com
Results 1 to 3 of 3

Thread: Error with XML DOM object

  1. #1
    Join Date
    Jun 2005
    Posts
    81

    Error with XML DOM object

    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:
    PHP Code:
    <% 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:

    Code:
    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:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <parent>
    <child name="Sally"></child>
    </parent>
    test2.xml
    Code:
    <?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
    Code:
    <% For i = 1 to 10 %>
    <!--#include file="wittyprogrammingcomment.inc"-->
    <% Next %>

  2. #2
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    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.

    Code:
    <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
    
    
    
    %>
    Last edited by russell_g_1; 10-02-2005 at 10:37 AM.

  3. #3
    Join Date
    Jun 2005
    Posts
    81
    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...
    Code:
    <% For i = 1 to 10 %>
    <!--#include file="wittyprogrammingcomment.inc"-->
    <% Next %>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles