XPath over XML Schema: Examples
Home Downloads
Contents
Sample XSD used in examples
Boilerplate
Examples: 1, 2, 3, 4, 5, 6 (more examples in the download).
Example 3: /ex:Collection//ex:*
public static List<PathElement> example3(SchemaData schData) {

    XPath xpath = new XPath("/ex:Collection//ex:*");

    // analyse XPath
    List<PathElement> matched = null;
    try {
        matched = xpath.analyse(schData, null);
    } catch (XPathException e) {
        System.err.println(e.getMessage());
    }

    // only keep elements with "minOccurs = '1'"
    List<PathElement> good = new LinkedList<PathElement>();
    for (PathElement pe: matched) {
        Node node = pe.getNode();
        if (node != null && node.getMinOccurs() == 0)
            good.add(pe);
    }
    
    // print good nodes
    printMatchedNodes(good);
    
    return good;
}
    
Output
Matched nodes:
/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)    
    
SourceForge.net Logo Hit Counter