SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    import xml with asp

    I am trying to import some xml into an asp page for manuipulation. I have:

    Code:
    <%
    Dim xmlDoc
    Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
    xmlDoc.async=false  
    xmlDoc.load(Server.MapPath("xmldata/2006-07_JUL-SEP.xml"))
    xmlDoc.load(Request) 
    If xmlDoc.parseError.errorcode<>0 then
    	'error handling code
    	Response.Write(xmlDoc.parseError.errorcode)
    Else
    	'proceed
    	Response.Write("Everthing OK so far!")
    End If
    %>
    I get :

    error = -1072896680

    is it obvious where i'm going wrong (the xml is valid)?

    monkey
    monkey - the rest is history

  2. #2
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first thing to do is open the xml file in IE, of there is a problem, it will let you know.

  3. #3
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and is that error being written by this line: Response.Write(xmlDoc.parseError.errorcode) or does it point to a different line in your script?

  4. #4
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    done that - and run it through the w3c xml validator and everthing seems fine. seems to work if I remove the line:

    xmlDoc.load(Request)

    What I need is a good tutorial on how I can manipulate the data and use it in my asp code.

    cheers

    the response.write line
    monkey - the rest is history

  5. #5
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://msdn.microsoft.com/xml/default.aspx

    there is an sdk/help file that can be download with all the code samples that you'd ever want. also maybe check out the "code samples" link.

  6. #6
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers bill

    I have already read the 4guysfromrolla article (the MSDN site keeps crashing on me!!!) and a few others, but they all seem to eaither use the xsl to display the entire xml data, or just write the whole lot out using asp.

    I need far more control over the data, targeting the data in spacific elements. Treating it more like a recordset.

    any ideas

    cheers
    monkey - the rest is history

  8. #8
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's been a while since i've done it, but with MSXML you can target individual nodes or even return node collections. check into the sdk, not sure where it is on the site anymore. maybe do a google on the msxml sdk

  9. #9
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  10. #10
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    top man - i'll give it a read - cheers
    monkey - the rest is history

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Location
    San Francisco, CA
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was curious as to why you even had that line
    xmlDoc.load(Request)

    The other load call is the on the one you want.

    I see you are using the XMLDom so it uses pretty standard methods for accessing elements, tags and some
    xmlDoc.getElementById
    xmlDoc.getElementsByTagName
    xmlDoc.childNodes
    etc.

    W3schools is always a great reference for this kind of stuff:
    http://w3schools.com/dom/default.asp

  12. #12
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been reading the w3schools tutorials, but they are all in javascript and from what I can tell, I should be able to do the same thing in asp vbscript.

    I am trying:

    Code:
    <%
    Dim xmlDoc
    Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
    xmlDoc.async=false  
    xmlDoc.load(Server.MapPath("xmldata/myxmlfile.xml"))
    
    If xmlDoc.parseError.errorcode<>0 then
    	'error handling code
    	Response.Write(xmlDoc.parseError.errorcode)
    Else
    	'proceed
    	Response.Write(xmlDoc.getElementsByTagName("DataReturn"))
    End If
    %>
    This gives the error: Missing Default property' - where am I going wrong. I'm sure once I get one basic thing to work, the rest will drop into place

    cheers
    monkey - the rest is history

  13. #13
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Response.Write xmlDoc.getElementsByTagName("DataReturn").xml

  14. #14
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser
    Response.Write xmlDoc.getElementsByTagName("DataReturn").xml
    Object doesn't support this property or method: 'getElementsByTagName(...).xml'
    monkey - the rest is history

  15. #15
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about
    xmlDoc.selectSingleNode("DataReturn").xml

  16. #16
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fantastic!

    How do I move down through the tree? ie:

    <dataReturn>
    <node></node>
    </dataReturn>

    How do i get to node?

    cheers for your help
    monkey - the rest is history

  17. #17
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    either
    Code:
    Set oMyNode = xmlDoc.selectSingleNode("dataReturn/node")
    Response.Write oMyNode.xml
    or if you need the DataReturn node first:
    Code:
    Set oDataReturn = xmlDoc.selectSingleNode("dataReturn")
    Set oMyNode = oDataReturn.selectSingleNode("node")
    etc
    dont forget that xpath is case sensitive

  18. #18
    SitePoint Wizard boxhead's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    1,040
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers - started to get to grips with it now

    How do I get a list of attribute for a set of node (sorry, not sure of the language to use!)

    so if i have:

    <mynode>
    <child attribute="x">45</child>
    <child attribute="y">12</child>
    </mynode>

    I would like an array of the attributes or, better still, be able to loop through every child in a certain node and response.write the attribute value such as

    for each child in mynode
    response.write("attribute.value"&"</br>")
    response.Write(xmlDoc.selectSingleNode("mynode/child[@attribute="&attribute.value&"]")
    next

    if you see what i mean

    cheers
    monkey - the rest is history

  19. #19
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for each child in mynode.selectNodes("child")
    response.write("attribute.value"&"</br>")
    response.Write(child.getAttribute("attribute"))
    next


Bookmarks

Posting Permissions

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