Android XPath Create newXPath()

Here you can find the source of newXPath()

Description

Creates a new XPath object using the default prefix for the android namespace.

License

Apache License

Declaration

public static XPath newXPath() 

Method Source Code

/*//from   w  w w. j a va 2  s .  c  om
 * Copyright (C) 2009 The Android Open Source Project
 *
 * 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.
 */

import com.android.SdkConstants;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.namespace.NamespaceContext;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;

public class Main{
    private static final XPathFactory sFactory = XPathFactory.newInstance();
    /**
     * Creates a new XPath object, specifying which prefix in the query is used for the
     * android namespace.
     * @param androidPrefix The namespace prefix.
     */
    public static XPath newXPath(String androidPrefix) {
        XPath xpath = sFactory.newXPath();
        xpath.setNamespaceContext(new AndroidNamespaceContext(androidPrefix));
        return xpath;
    }
    /**
     * Creates a new XPath object using the default prefix for the android namespace.
     * @see #DEFAULT_NS_PREFIX
     */
    public static XPath newXPath() {
        XPath xpath = sFactory.newXPath();
        xpath.setNamespaceContext(AndroidNamespaceContext.getDefault());
        return xpath;
    }
}

Related

  1. newXPath(String androidPrefix)
  2. getXPath()
  3. getXpathExpression(String s)