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

StringgetXmlString(Node inXml, String xpath)
get Xml String
if (!xpath.contains("/")) {
    NodeList elements = ((Element) inXml).getElementsByTagName(xpath);
    if (elements.getLength() == 1) {
        return elements.item(0).getTextContent();
try {
    return xPath.evaluate(xpath, inXml);
...
XPathgetXPath()
Creates a new XPath object, without namespace context or other configuration.
return factory.newXPath();
XPathgetXPath()
get X Path
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
return xpath;
XPathgetXpath()
get Xpath
try {
    XPath xpath = xpathTL.get();
    if (xpath == null) {
        xpath = XPathFactory.newInstance().newXPath();
        xpathTL.set(xpath);
    return xpath;
} catch (Exception e) {
...
XPathgetXPath()
Gets the XPath API, creating it if necessary.
if (xpath == null) {
    xpath = getXPathFactory().newXPath();
return xpath;
XPathgetxPath()
getx Path
return xPathFactory.newXPath();
ThreadLocalgetXPath()
get X Path
if (xPath == null) {
    xPath = new ThreadLocal<XPath>() {
        @Override
        protected XPath initialValue() {
            return XPathFactory.newInstance().newXPath();
    };
return xPath;
StringgetXPath(Element elt)
get X Path
String xpath = "";
if (elt != null) {
    Document doc = elt.getOwnerDocument();
    Element root = doc.getDocumentElement();
    Element parent = elt;
    while (parent != root) {
        xpath = "/" + parent.getNodeName() + xpath;
        parent = (Element) parent.getParentNode();
...
StringgetXPath(Element rootElement, Element targetElement, boolean includeElementIndex, Map namespacesMap)
Returns the XPath to retrieve targetElement from rootElement.
Stack<Element> elementPath = new Stack<Element>();
Map<String, String> namespaceUriToIdMap = new HashMap<String, String>();
for (Entry<String, String> entry : namespacesMap.entrySet()) {
    namespaceUriToIdMap.put(entry.getValue(), entry.getKey());
    Element currentElement = targetElement;
    while (currentElement != null && currentElement != rootElement) {
...
XPathgetXPath(NamespaceContext nsContext)
get X Path
XPath xpath = XPathFactory.newInstance().newXPath();
if (nsContext != null)
    xpath.setNamespaceContext(nsContext);
return xpath;