Parse our portion of XML using ASP

Discussion in 'ASP General' started by Joey Martin, Jan 15, 2008.

  1. Joey Martin

    Joey Martin Guest

    I'll try to make my explanation as thorough as possible.

    I am trying to grab the value of the node that is returned.

    MY CODE:
    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    xmlhttp.open "POST"
    Set xmldom = CreateObject("Microsoft.XMLDOM")
    xmldom.loadXML thexml2
    xmlhttp.send xmldom
    response.Write(xmlhttp.responseText)

    I left out some of the above code, but the code works and the results
    are returned correctly. Here are the results I receive:
    <?xml version="1.0" encoding="utf-8"?>
    <response xmlns="xxxxxxx.com" status="ok">
    <clients page="1" per_page="25" pages="1" total="1">
    <client>
    <client_id>70</client_id>
    <username></username>
    </client>
    </clients>
    </response>


    I want to grab the CLIENT_ID value, that's it. I need to set that as a
    variable in my current code.

    Please help. And thank you in advance.



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Joey Martin, Jan 15, 2008
    #1
    1. Advertising

  2. "Joey Martin" <> wrote in message
    news:...
    > I'll try to make my explanation as thorough as possible.
    >
    > I am trying to grab the value of the node that is returned.
    >
    > MY CODE:
    > Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    > xmlhttp.open "POST"
    > Set xmldom = CreateObject("Microsoft.XMLDOM")
    > xmldom.loadXML thexml2
    > xmlhttp.send xmldom
    > response.Write(xmlhttp.responseText)
    >
    > I left out some of the above code, but the code works and the results
    > are returned correctly. Here are the results I receive:
    > <?xml version="1.0" encoding="utf-8"?>
    > <response xmlns="xxxxxxx.com" status="ok">
    > <clients page="1" per_page="25" pages="1" total="1">
    > <client>
    > <client_id>70</client_id>
    > <username></username>
    > </client>
    > </clients>
    > </response>
    >
    >
    > I want to grab the CLIENT_ID value, that's it. I need to set that as a
    > variable in my current code.
    >
    > Please help. And thank you in advance.
    >



    To 'grab' a value from XML you can use the DOMs selectSingleNode method:-

    Set oElem = oSomeDOM.selectSingleNode("/response/clients/client/client_id")
    sID = oElem.text

    It would be in your interest to tell us what it is you trying to achieve and
    show use more of your code. For example you've left out the xmlhttp.open
    call.

    Do you control the remote site to which you are posting?
    Does it ensure that the response content type is marked as an xml type?

    Replace Microsoft.XMLHTTP with MSXML2.ServerXMLHTTP.3.0.

    If all you are doing with the xmldom is passing it to send then consider
    sending the string instead:-

    xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=UTF-8"
    xmlhttp.send thexml2

    That way you avoid the significant xml parsing and DOM creation.

    If you let us know more about what the code's purpose is we may be able to
    give you a more complete answer.

    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 15, 2008
    #2
    1. Advertising

  3. Joey Martin

    Joey Martin Guest

    I am "posting" my XML code and then given xml code back to me with
    results based on my initial post. Here is my complete code:
    <%
    thexml2=thexml2 & "<?xml version='1.0' encoding='utf-8'?>"
    thexml2=thexml2 & "<request method='client.list'>"
    thexml2=thexml2 & " <email></email>"
    thexml2=thexml2 & "</request>"
    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")

    xmlhttp.open "POST" ,"https://xxx.xxx.com/api/2.1/xml-in",False, "xxx"
    , "X"
    xmltext = thexml
    Set xmldom = CreateObject("Microsoft.XMLDOM")
    xmldom.loadXML thexml2
    xmlhttp.send xmldom
    response.Write(xmlhttp.responseText)


    Returned is:
    <?xml version="1.0" encoding="utf-8"?>
    <response xmlns="xxxxxxx.com" status="ok">
    <clients page="1" per_page="25" pages="1" total="1">
    <client>
    <client_id>70</client_id>
    <username></username>
    </client>
    </clients>
    </response>


    Again, all I care about it the Client ID value.



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Joey Martin, Jan 15, 2008
    #3
  4. "Joey Martin" <> wrote in message
    news:...
    > I am "posting" my XML code and then given xml code back to me with
    > results based on my initial post. Here is my complete code:
    > <%
    > thexml2=thexml2 & "<?xml version='1.0' encoding='utf-8'?>"
    > thexml2=thexml2 & "<request method='client.list'>"
    > thexml2=thexml2 & " <email></email>"
    > thexml2=thexml2 & "</request>"
    > Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    >
    > xmlhttp.open "POST" ,"https://xxx.xxx.com/api/2.1/xml-in",False, "xxx"
    > , "X"
    > xmltext = thexml
    > Set xmldom = CreateObject("Microsoft.XMLDOM")
    > xmldom.loadXML thexml2
    > xmlhttp.send xmldom
    > response.Write(xmlhttp.responseText)
    >
    >
    > Returned is:
    > <?xml version="1.0" encoding="utf-8"?>
    > <response xmlns="xxxxxxx.com" status="ok">
    > <clients page="1" per_page="25" pages="1" total="1">
    > <client>
    > <client_id>70</client_id>
    > <username></username>
    > </client>
    > </clients>
    > </response>
    >
    >
    > Again, all I care about it the Client ID value.
    >



    Assuming the remote service has correctly set its Content-Type response
    header then:-

    sClientId = xmlhttp.ResponseXML.selectSingleNode("//client_id").Text

    If that doesn't work (because ResponseXML is not set then try)

    Dim oDOM : Set oDOM = CreateObject("MSXML2.DOMDocument.3.0")
    oDOM.loadXML xmlhttp.responseText
    sClientId = oDOM.selectSingleNode("//client_id").Text


    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Jan 15, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NETRavi via DotNetMonster.com

    ASP.NET : Capturing a portion of a web page into a jpeg file

    NETRavi via DotNetMonster.com, Nov 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    341
    NETRavi via DotNetMonster.com
    Nov 17, 2005
  2. Learner
    Replies:
    3
    Views:
    3,964
    venkatmath
    Jul 12, 2008
  3. johndesp
    Replies:
    1
    Views:
    10,517
    Martin Honnen
    Jan 19, 2004
  4. Savvoulidis Iordanis

    Reading only a specific portion of XML file.

    Savvoulidis Iordanis, Dec 14, 2009, in forum: ASP .Net
    Replies:
    3
    Views:
    451
    Alexey Smirnov
    Dec 15, 2009
  5. IlyaK
    Replies:
    2
    Views:
    1,484
    IlyaK
    Jan 21, 2010
Loading...

Share This Page