Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Displaying a single element / node from server 1

Status
Not open for further replies.

craigward

Programmer
Nov 13, 2007
230
GB
Hi,
For many months I have been trying to get parse XML data to the HSBC payment gateway. Finally, I can get the data from a form to the server in XML and receive a reply. This is great but I get a whole load of xml back and I need to pull only certain elements.

Could anyone see what I can do with this(Response.Write xmlhttp.responsexml.xml) to change it to pull <FileTime></FileTime> out without all the other XML nodes?

Any help would be great thanks a lot.


CODE:

<%@ Language=vbScript%>
<%

'value = Request.Form("id")
cardtype = "Mastercard" 'Request.Form
cardauth = "cardsuth" ' FIND THIS FROM 170

cardnumber = Request.Form("cardnumber")
expirydate = Request.Form("cardnumber")
amount = Request.Form("amount")

DataToSend = "<EngineDocList><DocVersion DataType='String'>1.0</DocVersion><EngineDoc><ContentType DataType='String'>OrderFormDoc</ContentType><User><ClientId DataType='S32'>12121</ClientId><Name DataType='String'>XML Payments</Name><Password DataType='String'>password</Password></User><Instructions><Pipeline DataType='String'>PaymentNoFraud</Pipeline></Instructions><OrderFormDoc><Mode DataType='String'>Y</Mode><Consumer><PaymentMech><Type DataType='String'>" & cardtype & "</Type><CreditCard><Number DataType='String'>" & cardnumber & "</Number><Expires DataType='ExpirationDate' Locale='826'>" & expirydate & "</Expires></CreditCard></PaymentMech></Consumer><Transaction><Type DataType='String'>" & cardauth & "</Type><CurrentTotals><Totals><Total DataType='Money' Currency='826'>" & amount &"</Total></Totals></CurrentTotals></Transaction></OrderFormDoc></EngineDoc></EngineDocList>"

dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST"," xmlhttp.setRequestHeader "Content-Type", "application/x- xmlhttp.send DataToSend
Response.ContentType = "text/xml"

Response.Write xmlhttp.responsexml.xml





Set xmlhttp = nothing

%>
 
Modulo missing detail, try this.
[tt]
'Response.Write xmlhttp.responsexml.xml 'replacing this line by the below
set odoc=xmlhttp.responsexml.documentElement
set onode=odoc.SelectSingleNode("//FileTime")
response.write onode.xml
[/tt]
 
Thank you very much for this. I have one more small question. If i want to extract the value from the xml. Is that possible? The result i get is <FileTime DataType="String">19:43:05Nov 6 2006</FileTime> I would like to pull the 19:43:05Nov 6 2006 to the page.

Thank you agin so much.
 
It can be simply got like this.
[tt] s=onode.text 's returns "19:43:05Nov 6 2006"[/tt]
 
Thanks for your quick replies.

I tried this at the end and got the error below. Is it somthing to do with needing a style sheet? as you can see i am completely new to XML

Thanks.

CODE---------------

set odoc=xmlhttp.responsexml.documentElement
set onode=odoc.SelectSingleNode("//FileTime")
'response.write onode.xml
s=onode.text

response.write(s)


Error-------------

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource ' Line 1, Pos...

19:43:05Nov 6 2006
 
Since you have
[tt]response.content-type=text/xml"[/tt]
you should be sending:
[tt]response.write onode.xml[/tt]
or perhaps mentally more challenging:
[tt]response.write onode[/tt]
If you want to send onode.text, comment out the content-type setting.
 
Thanks for that, i know it is simple to you but it has taken a long time to find someone to make it clear.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top