XPath over XML Schema: Examples
Contents
Sample XSD used in examples Boilerplate
Examples: 1, 2, 3, 4, 5, 6 (more examples in the download).
Example 1: //ex:Address
public static List<PathElement> example1(SchemaData schData) { XPath xpath = new XPath("//ex:Address"); // analyse XPath List<PathElement> matched = null; try { matched = xpath.analyse(schData, null); } catch (XPathException e) { System.err.println(e.getMessage()); } // print matched nodes printMatchedNodes(matched); return matched; }
Output
Matched nodes: /Address[1,1](10:3) /Delivery[1,1](23:3)/Address[1,1](29:7) /Addresses[1,1](34:3)/Address[0,inf](38:7) /Deliveries[1,1](42:3)/Delivery[0,inf](46:7)/Address[1,1](29:7) /Collection[1,1](50:3)/Addresses[1,1](53:7)/Address[0,inf](38:7) /Collection[1,1](50:3)/Deliveries[1,1](54:7)/Delivery[0,inf](46:7)/Address[1,1](29:7)