Parsing XML with JavaScript question - Newbie Help

Jason Jodon

Usenet Archive
Joined
Oct 14, 2003
Messages
3
Reaction score
0
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="">

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,050
Messages
3,104,249
Members
248,133
Latest member
DujonT

Latest Threads

Top