Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Constructing XPath Query

Reply
Thread Tools

Constructing XPath Query

 
 
simonverona87@googlemail.com
Guest
Posts: n/a
 
      02-04-2013
Hi,

I am a little rusty on using XPath - not having had used it in a couple of years

I have an xmldocument - coming from a restful web service and being processed in vb.net .

The xml resembles the following layout :-

<result>
<requests>
<request>
<form name="id">1234</form>
<form name="customer"> ABC </form>
</request>
<request>
<form name="id">1235 </form>
<form name="customer"> DEF</form>
</request>
....
....
</requests>
</result>

I want to be able to count how many requests there are for specific customers (perhaps more than one at once) and thought I could do this by using an xpath query to return a nodelist which selects the nodes which are of the "form" element with the "name" attribute equal to "customer" then limiting the nodesselected where the customer name is one of the customers im lookingford (eg ABC and DEF).

Once I have the nodelist ill be able to count the nodes in the result.

I just cant form the xpath query though! The closest ive got is /result/requests/request/form[@name='customer'] which selects all the customer nodes, but I cant work out how to then limit the nodes selected to be for only certain customers.....

Can anybody point me in the right direction?

Thanks
Simon
 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      02-04-2013
* http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in comp.text.xml:
>The xml resembles the following layout :-
>
><result>
><requests>
><request>
><form name="id">1234</form>
><form name="customer"> ABC </form>
></request>
><request>
><form name="id">1235 </form>
><form name="customer"> DEF</form>
></request>
>...
>...
></requests>
></result>


>I just cant form the xpath query though! The closest ive got is
>/result/requests/request/form[@name='customer'] which selects all the
>customer nodes, but I cant work out how to then limit the nodes selected
>to be for only certain customers.....


Something like

/result/requests/request[form[@name='customer' and . = 'DEF']]

would select `request` elements that have a `form` child that has a
`name` attribute with the value identical to 'customer' and a string
value identical to 'DEF'. You might want to put normalize-space() a-
round the `.` (which stands for the "context node", the `form` element
in your case).
--
Björn Höhrmann · (E-Mail Removed) · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      02-05-2013
On 2/4/2013 2:54 PM, Bjoern Hoehrmann wrote:
> /result/requests/request[form[@name='customer' and . = 'DEF']]


Or, if there's one form per request:
/result/requests/request/form[@name='customer' and . = 'DEF']
or
/result/requests/request/form[@name='customer'][. = 'DEF']
or...

In XPath, as in most expression languages, there are usually multiple
ways to accomplish the same result. Which is most efficient may depend
on the quirks of a particular processor.

--
Joe Kesselman,
http://www.love-song-productions.com...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."
 
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
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
JDBC - Constructing a query realtime Mohammad S Khan Java 0 10-31-2003 12:03 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments