Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Parsing XML with Javascript - newbie question

Reply
Thread Tools

Parsing XML with Javascript - newbie question

 
 
Jason Jodon
Guest
Posts: n/a
 
      12-11-2003
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%>
 
Reply With Quote
 
 
 
 
Andy Dingley
Guest
Posts: n/a
 
      12-13-2003
On 11 Dec 2003 06:18:48 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
Parsing XML with JavaScript question - Newbie Help Jason Jodon Javascript 0 12-11-2003 02:17 PM
XML Parsing - newbie question Marcio DeBarros XML 1 10-05-2003 07:38 PM



Advertisments