Here you can find the source of buildPathArray(String xpath)
public static String[] buildPathArray(String xpath)
//package com.java2s; /*/*from ww w . j a v a2 s. c om*/ * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Build the input for the get...FromPath methods. If the XPath * expression cannot be handled by the methods, <code>null</code> * is returned. */ public static String[] buildPathArray(String xpath) { String[] result = null; if (xpath != null && xpath.charAt(0) != '/') { // test int components = 1; int i, l; l = xpath.length(); boolean found = false; i = 0; while (i < l && found == false) { switch (xpath.charAt(i)) { case '[': found = true; break; case '(': found = true; break; case '*': found = true; break; case '@': found = true; break; case ':': found = true; break; case '/': components++; default: i++; } } if (found == false) { result = new String[components]; if (components == 1) { result[components - 1] = xpath; } else { i = 0; int start = 0; components = 0; while (i < l) { if (xpath.charAt(i) == '/') { result[components] = xpath.substring(start, i); start = i + 1; components++; } i++; } result[components] = xpath.substring(start); } } } return result; } }