Saturday, March 8, 2014

Powerful Xpaths

XPATHs are powerful way to traverse and query the xml documents. I am listing here some of the useful xpaths and their meaning to keep it handy.

purchaseOrder - select all nodes with the name purchaseOrder
/purchaseOrder - select the root element purchaseOrder
/purchaseOrder/items - select all item elements that are children of purchaseOrder
//items - select all items elements irrespective of their locations in the entire document
purchaseOrder//items - select all items child element of purchaseOrder irrespective of their location under purchaseOrder element.
/purchaseOrder/* - select all child nodes of purchaseOrder element.
// - select all elements in the document
/purchaseOrder/items[last()] - select the last items element of purchase order.
/purchaseOrder/items[position()<3] - select first two items child elements for purchaseOrder
//items[@partNum] - select all elements that have attribute name 'partNum'
//items[@partNum='123'] - select all items elements that have attribute name 'partNum' having value 123
/items/item[price>300] - select all item element under items that have 'price' element with value greater than 300.



No comments:

Post a Comment

Demystifying OIC, OCI and Oracle SOA CS

What is OIC (Oracle integration cloud), OCI (Oracle cloud infrastructure), and SOA cloud service and how they are different? - This has bee...