Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import com.google.common.base.Strings;

public class Main {
    /**
     * @param xpath
     *            The xpath expression.
     * @return the xpath expression for only the element location. Leaves out the attributes and
     *         text()
     */
    public static String stripXPathToElement(String xpath) {
        String xpathStripped = xpath;

        if (!Strings.isNullOrEmpty(xpathStripped)) {
            if (xpathStripped.toLowerCase().contains("/text()")) {
                xpathStripped = xpathStripped.substring(0, xpathStripped.toLowerCase().indexOf("/text()"));
            }
            if (xpathStripped.toLowerCase().contains("/comment()")) {
                xpathStripped = xpathStripped.substring(0, xpathStripped.toLowerCase().indexOf("/comment()"));
            }
            if (xpathStripped.contains("@")) {
                xpathStripped = xpathStripped.substring(0, xpathStripped.indexOf("@") - 1);
            }
        }

        return xpathStripped;
    }
}