Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
How to write xpath to get matching node based on the node's attributes and childs (if any) attributes

single xml node:

XML
<Nokia_3220.gif jcr:primaryType="nt:file" jcr:uuid="90ff297d-7508-4cc8-8302-71b6e75fb8ba" jcr:created="2014-01-03T04:51:24.377-08:00" jcr:createdBy="admin">
<jcr:content jcr:primaryType="nt:unstructured" country="India" firstName="Supplier" jcr:data="FBAAOw==" jcr:lastModified="2014-01-03T18:21:11.216+05:30" jcr:mimeType="image/gif" lastName="Image1" phone="988-777-5551" state="WB" status="Active"/>
</Nokia_3220.gif>


what would be the xpath query for jcr:uuid and state and firstName and jcr:created all are like search ?

I tried :

string xpath =
SQL
"//Nokia_3220.gif[contains(translate(@jcr:uuid, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'90ff297d-7508-4cc8-8302-71b6e75fb8ba')
and contains(translate(@state, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'W')
and contains(translate(@firstName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'pplie')]



xmlnodelist list = objDoc.selectnodes(xpath,ns);

my problem is I can't predict , whether a particular attribute belongs to a node itself or it belongs to its child.

How to write xpath to get the node irrespective of the attribute attached to the node or its child, provided the name of the element which contains the attribute for sure

hope , you understand

any suggestions is appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900