This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > February 2005 > XPath Query: How?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author XPath Query: How?
MGBloomfield

2005-02-20, 7:25 am

Here's an XML file that I want to query using XPath. Using XPath, I want to
get the element value of Status where ACHTransaction sequence_id="1" which
would be APPROVED.

<?xml version="1.0" encoding="UTF-8"?>
<TransactionBatch xmlns="capture"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="capture
https://secure.domain.net/specification/transaction.xsd">
<ACHTransaction sequence_id="1">
<Sale>
<Customer>
<CustomerID>654321</CustomerID>
<SaleID>10007654321</SaleID>
<Status>APPROVED</Status>
</Sale>
</ACHTransaction>
<ACHTransaction sequence_id="2">
<Refund>
<SaleID>1000143454</SaleID>
<Amount>34.95</Amount>
<Status>SUCCESS</Status>
</Refund>
</ACHTransaction>
</TransactionBatch>

Bjoern Hoehrmann

2005-02-20, 7:25 am

* MGBloomfield wrote in microsoft.public.xml:
>Here's an XML file that I want to query using XPath. Using XPath, I want to
>get the element value of Status where ACHTransaction sequence_id="1" which
>would be APPROVED.


Your XML is not well-formed (the <Customer> element is not closed) so I
need to guess how the document might look like... Generally something
like

_ string(/x:TransactionBatch/x:ACHTransaction[@sequence_id="1"]/x:Sale/x:Status)

should do it, assuming you've bound the prefix 'x' to the right
namespace.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews