Parsing XML with Javascript - newbie question

Discussion in 'XML' started by Jason Jodon, Dec 11, 2003.

  1. Jason Jodon

    Jason Jodon Guest

    I'm need to get the value of the Credential domain from the XML below.
    I am really new to XML and would appreciate any help. I am able to
    pull the other element values but the attribute vaulue eludes me. I
    guess I don't understand slice very well. Please help!!!!


    XML sample:
    <cXML xml:lang="en-US" timestamp="2003-12-11T04:28:06-08:00"
    payloadID="1071145686133-1346883382556734385@216.109.111.41">

    <Header>
    <From>
    <Credential domain="NetworkID">
    <Identity>AN01000002779-T</Identity>
    </Credential>
    </From>

    <To>
    <Credential domain="DUNS">


    ======================

    My code:
    <script language=JScript RUNAT=Server>
    function elementValue(xml, elem)
    {
    var begidx;
    var endidx;
    var retStr;

    begidx = xml.indexOf(elem);
    if (begidx > 0) {
    endidx = xml.indexOf('</',begidx);
    if (endidx > 0)
    retStr = xml.slice(begidx+elem.length,
    endidx);
    return retStr;
    }
    return null;
    }


    function DomainValue(xml, elem)
    {
    var begidx;
    var endidx;
    var retStr;

    begidx = xml.indexOf(elem);
    if (begidx > 0) {
    endidx = xml.indexOf('</',begidx);
    if (endidx > 0)
    retStr = xml.slice(begidx+elem.length,
    endidx);
    return retStr;
    }
    return null;
    }


    </script>
    <%
    REM this will take the PunchOutSetup request coming from Ariba Network
    REM take the ORMSURL and buyercookie attach it to the startpage URL
    and
    REM and send the response back to the ORMS.
    REM punchoutredirect.asp?bc=21343hfefe&url="http://ariba.cisco/com/..&redirect="
    Dim ret
    Dim punch
    Dim statusText
    Dim statusCode
    Dim cookie
    Dim url
    Dim xmlstr
    Dim fromDomain
    Dim fromUser
    Dim toDomain
    Dim toUser
    cookie = ""
    url = ""
    xmlstr = ""
    dir = ""
    path = Request.ServerVariables("PATH_INFO")
    dir = Left(path, InstrRev(path, "/"))
    if IsEmpty(dir) then
    dir = "/"
    end if

    REM This command reads the incoming HTTP cXML Request
    xml = Request.BinaryRead(Request.TotalBytes)
    for i = 1 to Request.TotalBytes
    xmlstr = xmlstr + String(1,AscB(MidB(xml, i,
    1)))
    REM
    REM SUPPLIER SHOULD INSERT XML PARSER METHOD CALL HERE
    REM
    Next
    cookie = elementValue(xmlstr, "<BuyerCookie>")
    url = elementValue(xmlstr, "<URL>")
    fromDomain = DomainValue(xmlstr, "<Identity>")
    fromUser = elementValue(xmlstr, "<Identity>")
    newXMLStr = Right(xmlstr, Len(xmlstr) -
    (InStr(xmlstr,"<Identity>") + Len("<Identity>")))
    toDomain = DomainValue(newXMLstr, "<Identity>")
    toUser = elementValue(newXMLStr, "<Identity>")%>


    <%
    REM This following formats the cXML PunchOutSetupReponse
    if IsEmpty(cookie) then
    %>
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE cXML SYSTEM "cXML.dtd">
    <cXML version="1.0" payloadID="<%= Now &"@"&
    Request.ServerVariables("LOCAL_ADDR")%>" timestamp="<%= Now %>">
    <Response>
    <Status code="500" text="Invalid document"/>
    </Response>
    </cXML>
    <% else %>
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE cXML SYSTEM "cXML.dtd">
    <cXML version="1.0" payloadID="<%= Now &"@"&
    Request.ServerVariables("LOCAL_ADDR")%>" timestamp="<%= Now %>">
    <Response>
    <Status code="200" text="OK"/>
    <PunchOutSetupResponse>
    <StartPage>
    <URL>https://punchout.stateindustrial.com/<%=
    dir%>/selection.asp?bc=<%= cookie%>&amp;url=<%= url%>&amp;fromDom=<%=
    FromDomain%>&amp;from=<%= fromUser%>&amp;toDom=<%=
    ToDomain%>&amp;to=<%= toUser%>&amp;redirect=<%= StartPage%></URL>
    </StartPage>
    </PunchOutSetupResponse>
    </Response>
    </cXML>
    <%end if%>
    Jason Jodon, Dec 11, 2003
    #1
    1. Advertising

  2. Jason Jodon

    Andy Dingley Guest

    On 11 Dec 2003 06:18:48 -0800, (Jason Jodon) wrote:

    >I'm need to get the value of the Credential domain from the XML below.
    >I am really new to XML and would appreciate any help.


    Use a DOM.

    Is this M$oft code ? Use MSXML
    Andy Dingley, Dec 13, 2003
    #2
    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. Marcio DeBarros

    XML Parsing - newbie question

    Marcio DeBarros, Oct 2, 2003, in forum: XML
    Replies:
    1
    Views:
    313
    Aidan
    Oct 5, 2003
  2. Originlabs
    Replies:
    0
    Views:
    451
    Originlabs
    Apr 23, 2008
  3. John Levine
    Replies:
    0
    Views:
    729
    John Levine
    Feb 2, 2012
  4. Jason Jodon
    Replies:
    0
    Views:
    113
    Jason Jodon
    Dec 11, 2003
  5. Erik Wasser
    Replies:
    5
    Views:
    450
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page