Java Utililty Methods XPath Create

List of utility methods to do XPath Create

Description

The list of methods to do XPath Create are organized into topic(s).

Method

XPathFactorygetXPathFactory()
get X Path Factory
return XPathFactory.newInstance();
XPathFactorygetXPathFactory()
get X Path Factory
if (_xPathFactory == null) {
    String magicValue = System
            .getProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom");
    System.setProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom",
            "net.sf.saxon.xpath.XPathFactoryImpl");
    _xPathFactory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
    if (magicValue == null)
        System.clearProperty("javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom");
...
XPathFactorygetXPathFactory()
get X Path Factory
return XPATH_FACTORY.get();
XPathFactorygetXPathFactory()
Gets the XPath factory, creating it if necessary.
if (xpathFactory == null) {
    xpathFactory = XPathFactory.newInstance();
return xpathFactory;
XPathFilterParameterSpecgetXpathFilter(String xpath, Map namespaceMap)
get Xpath Filter
XPathFilterParameterSpec params = namespaceMap == null ? new XPathFilterParameterSpec(xpath)
        : new XPathFilterParameterSpec(xpath, namespaceMap);
return params;
StringgetXPathForElement(Node e, NamespaceContext ctx)
get X Path For Element
StringBuffer sb = new StringBuffer();
List<Node> path = new ArrayList<Node>();
Node currentNode = e;
while (currentNode.getParentNode() != currentNode.getOwnerDocument()) {
    path.add(0, currentNode);
    if (currentNode instanceof Attr) {
        Attr a = (Attr) currentNode;
        currentNode = a.getOwnerElement();
...
StringgetXPathForNode(Node node)
Does a reverse walking of the DOM tree to generate a unique XPath expression leading to this node.
final StringBuilder sb = new StringBuilder();
Node parent = node;
while (parent != null && parent.getNodeType() != Node.DOCUMENT_NODE) {
    sb.insert(0, "]");
    sb.insert(0, getIndexInParent(parent) + 1);
    sb.insert(0, "[");
    sb.insert(0, parent.getNodeName());
    sb.insert(0, "/");
...
StringgetXPathForNode(Node node)
Does a reverse walking of the DOM tree to generate a unique XPath expression leading to this node.
String index = "";
if (node.getNodeType() == Node.ELEMENT_NODE) {
    int successors = 1;
    Node previous = node.getPreviousSibling();
    while (null != previous) {
        if (previous.getNodeType() == Node.ELEMENT_NODE
                && previous.getNodeName().equals(node.getNodeName())) {
            successors++;
...
StringgetXPathFromVector(Vector path)
get X Path From Vector
StringBuffer strBuf = new StringBuffer();
int length = path.size();
for (int i = 0; i < length; i++) {
    Node tempNode = (Node) path.elementAt(i);
    short nodeType = getNodeType(tempNode);
    String targetValue = getValue(tempNode, nodeType);
    int position = 1;
    tempNode = getPreviousTypedNode(tempNode, nodeType);
...
StringgetXPathFromVector(Vector path)
get X Path From Vector
StringBuffer strBuf = new StringBuffer();
int length = path.size();
for (int i = 0; i < length; i++) {
    Node tempNode = (Node) path.elementAt(i);
    short nodeType = getNodeType(tempNode);
    String targetValue = getValue(tempNode, nodeType);
    int position = 1;
    tempNode = getPreviousTypedNode(tempNode, nodeType);
...