how to extract text from an element in an xml string in classic asp

Fanat.Zet

New Member
I have the following xml:\[code\]<GetPurchaseContractResponse xmlns="http://payments.amazon.com/checkout/v2/2010-08-31/"> <GetPurchaseContractResult> <PurchaseContract> <Id>amzn1.contract.1.1.1.d6779be6bf481167fe945</Id> <State>ACTIVE</State> <MerchantId>XXXXXXXXXX</MerchantId> <ExpirationTimeStamp>2012-07-19T10:55:28.134Z</ExpirationTimeStamp> <MarketplaceId>A1SDFERWERSDF</MarketplaceId> </PurchaseContract> </GetPurchaseContractResult> <ResponseMetadata> <RequestId>0db53477-d17a-11e1-ac3e-fd3e0de62222</RequestId> </ResponseMetadata></GetPurchaseContractResponse>\[/code\]I want to extract the content of the ExpirationTimeStamp element.Here is the relevant piece of my code (yes we're using jscript and not vbscript):\[code\]var xmlDoc = Server.CreateObject("Msxml2.DOMDocument.6.0");xmlDoc.loadXML(xml);var expNode = xmlDoc.getElementsByTagName("ExpirationTimeStamp");if (expNode) Response.Write(expNode.text);\[/code\]I have also tried selectSingleNode instead of getElementsByTagNameI have tried GetPurchaseContractResponse/GetPurchaseContractResult/PurchaseContract/ExpirationTimeStamp as the xpath string with none, one and two leading forward slashesResponse.Write(xmlDoc.xml) outputs the entire document, so it is loading fine.The expNode variable doesn't get anything in it.My knowledge of xpath is next to nothing, so I'm sure some expert out there can point out the simple mistake I am making.
 
Back
Top