Skip navigation links
com.eibus.xml.xpath

Class XPath

    • Constructor Detail

      • XPath

        public XPath(java.lang.String sExpression)
        Deprecated. 
        Please use the factory method 'public static XPath getXPathInstance(String sExpression)' instead of this constructor. Constructor to create an XPathInstance with a specific XPath expression
        Parameters:
        sExpression - The Xpath expression that is to be evaluated.
    • Method Detail

      • getXPathInstance

        public static XPath getXPathInstance(java.lang.String sExpression)
        Factory method to create XPath object
        Parameters:
        sExpression - The Xpath expression that is to be evaluated.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text</table><chair/><table>abc</table></root>"
                                                .getBytes());
                XPath oXPath0 = XPath.getXPathInstance("string(//root/table)");
                XPathResult res = oXPath0.evaluate(iXml);
                assertEquals(XPathResult.XPATH_STRING, res.getType());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • getNumXPathObjects

        public static int getNumXPathObjects()
        Returns the total number of XPath objects created
        Returns:
        the total number of XPath objects.

        Example:
         <code>
         int res = XPath.getNumXPathObjects();
         </code>
         
      • getNumXPathExpressionObjects

        public static int getNumXPathExpressionObjects()
        Returns the total number of XPath Expression objects created
        Returns:
        the total number of XPath expression objects.

        Example:
         <code>
         int res = XPath.getNumXPathExpressionObjects();
         </code>
         
      • evaluateNumberResult

        public double evaluateNumberResult(int iNode)
        Evaluates the Xpath expression whose result is a Number.
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        a number ( floating point number )
        Note:  It returns '0' , if the result type of the XPath expression is not XPathResult.XPATH_NUMBER.

        Example:
                  
           String xml = "<root><table attr='5'>1</table><chair/></root>";
          Document oDocument = new Document();
          int iXml;
          try {
                iXml = oDocument.load(xml.getBytes());
                XPath oXPath = XPath.getXPathInstance("count(//root/table/@attr)");
                assertEquals(5, oXPath.evaluateNumberResult(iXml));
          } catch (XMLException e) {
                e.printStackTrace();
          }
          
         
      • evaluateNumberResult

        public double evaluateNumberResult(int iNode,
                                           XPathMetaInfo oMetaInfo)
        Evaluates the Xpath expression whose result is a Number.
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        a number ( floating point number )
        Note:  It returns '0' , if the result type of the XPath expression is not XPathResult.XPATH_NUMBER.

        Example:
                  
           String xml = "<root><table attr='5'>text</table><chair/></root>";
          Document oDocument = new Document();
          XPathMetaInfo meta = new XPathMetaInfo();
          meta.addNamespaceBinding("ns","http://www.xyz.com");
          int iXml;
          try {
                iXml = oDocument.load(xml.getBytes());
                XPath oXPath = XPath.getXPathInstance("count(//ns:root/ns:table/@attr)");
                assertEquals(5, oXPath.evaluateNumberResult(iXml, meta));
          } catch (XMLException e) {
                e.printStackTrace();
          }
          
         
         
      • evaluateBooleanResult

        public boolean evaluateBooleanResult(int iNode)
        Evaluates the Xpath expression whose result is a Boolean value.
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        boolean true or false as evaluated by the xpath expression
        Note:  It returns 'false' , if the result type of the XPath expression is not XPathResult.XPATH_BOOLEAN.

        Example:
          
           String xml = "<root><table attr='5'>text</table><chair/></root>";
          Document oDocument = new Document();
          int iXml;
          try {
                iXml = oDocument.load(xml.getBytes());
                XPath oXPath = XPath.getXPathInstance("//root/table/@attr!=4");
                assertEquals(true, oXPath.evaluateBooleanResult(iXml));
          } catch (XMLException e) {
                e.printStackTrace();
          }
          
         
      • evaluateBooleanResult

        public boolean evaluateBooleanResult(int iNode,
                                             XPathMetaInfo oMetaInfo)
        Evaluates the Xpath expression whose result is a Boolean value.
        Parameters:
        iNode - The NOM Handle to the input XML
        oMetaInfo - The XPathMetaInfo object
        Returns:
        boolean true or false as evaluated by the xpath expression
        Note: It returns 'false' , if the result type of the XPath expression is not XPathResult.XPATH_BOOLEAN.

        Example:
                 
           String xml = "<root xmlns='http://www.xyz.com'><table attr='5'>text</table><chair/></root>
          Document oDocument = new Document();
          XPathMetaInfo meta = new XPathMetaInfo();
          meta.addNamespaceBinding("ns","http://www.xyz.com");
          int iXml;
          try {
                iXml = oDocument.load(xml.getBytes());
                XPath oXPath = XPath.getXPathInstance("//ns:root/ns:table/@attr!=4");
                assertEquals(true, oXPath.evaluateBooleanResult(iXml, meta));
          } catch (XMLException e) {
                e.printStackTrace();
          }
          
         
         
      • evaluateStringResult

        public java.lang.String evaluateStringResult(int iNode)
        Evaluates the Xpath expression whose result is a String.
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        The string result
        Note:  It returns 'null' , if the result type of the xpath expression is not XPathResult.XPATH_STRING.

        Example:
                 
           String xml = "<root><table>text</table><chair/></root>";
          Document oDocument = new Document();
          int iXml;
          try {
                iXml = oDocument
                                .load(xml.getBytes());
                XPath oXPath = XPath.getXPathInstance("string(//root/table)");
                assertEquals("text", oXPath.evaluateStringResult(iXml));
          } catch (XMLException e) {
                e.printStackTrace();
          }
         
         
      • evaluateStringResult

        public java.lang.String evaluateStringResult(int iNode,
                                                     XPathMetaInfo oMetaInfo)
        Evaluates the Xpath expression whose result is a String.
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        The string result
        Note:  It returns 'null' , if the result type of the xpath expression is not XPathResult.XPATH_STRING.

        Example:
                 
           String xml = "<root xmlns='http://www.xyz.com'><table>text</table><chair/></root>";
          Document oDocument = new Document();
          XPathMetaInfo meta = new XPathMetaInfo();
           meta.addNamespaceBinding("ns","http://www.xyz.com");
          int iXml;
          try {
                iXml = oDocument
                                .load(xml.getBytes());
                XPath oXPath = XPath.getXPathInstance("string(//ns:root/ns:table)");
                assertEquals("text", oXPath.evaluateStringResult(iXml, meta));
          } catch (XMLException e) {
                e.printStackTrace();
          }
         
         
      • selectNodeSet

        public NodeSet selectNodeSet(int iNode,
                                     XPathMetaInfo oMetaInfo)
        Evaluates the Xpath expression taking XPathMetaInfo and NOM integer as input and returns result as a NodeSet.
        Parameters:
        iNode - The NOM integer handle.
        oMetaInfo - The MetaInfo object
        Returns:
        Result as a NodeSet object

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPath oXPath0 = XPath.getXPathInstance("//root/html4:table");
                NodeSet oNodeset = oXPath0.selectNodeSet(iXml, meta);
                assertEquals(1, oNodeset.size());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • selectNodeSet

        public NodeSet selectNodeSet(long iResultNode,
                                     XPathMetaInfo oMetaInfo)
        Evaluates the Xpath expression taking XPathMetaInfo and ResultNode handle as input and returns result as a NodeSet.
        Parameters:
        iResultNode - The Result Node handle.
        oMetaInfo - The MetaInfo object
        Returns:
        Result as a NodeSet object

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><child1><gchild1><ggchild1/></gchild1></child1></root>"
                                                .getBytes());
         
                XPath oXPath0 = XPath.getXPathInstance("//child1");
                NodeSet oNodeset = oXPath0.selectNodeSet(iXml, null);
         
                long iResultNode = oNodeset.next();
                oXPath0 = XPath.getXPathInstance("//ggchild1");
                oNodeset = oXPath0.selectNodeSet(iResultNode, null);
         
                iResultNode = oNodeset.next();
                assertEquals("ggchild1", ResultNode.getName(iResultNode));
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • selectNodeSet

        public NodeSet selectNodeSet(int iNode)
        Evaluates the Xpath expression taking NOM integer as input
        Parameters:
        type - The NOM integer
        Returns:
        Result as a NodeSet object

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text</table><chair/></root>".getBytes());
                XPath oXPath0 = XPath.getXPathInstance("//root/table");
                NodeSet oNodeset = oXPath0.selectNodeSet(iXml);
                assertEquals(1, oNodeset.size());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • selectNodeSet

        public NodeSet selectNodeSet(long iResultNode)
        Evaluates the Xpath expression taking ResultNode handle as input
        Parameters:
        iResultNode - The ResultNode handle
        Returns:
        Result as a NodeSet object

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text<chair/></table></root>".getBytes());
                XPath oXPath0 = XPath.getXPathInstance("//root/table");
                NodeSet oNodeset = oXPath0.selectNodeSet(iXml);
                long iResNode = oNodeset.next();
                oXPath0 = XPath.getXPathInstance("//table/chair");
                oNodeset = oXPath0.selectNodeSet(iResNode);
                assertEquals(1, oNodeset.size());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • evaluate

        public XPathResult evaluate(int iNode)
        Evaluates the Xpath expression to the most generic result form XPathResult taking the NOM integer as input.
        Parameters:
        iNode - The NOM integer handle
        Returns:
        Result as a XPathResult object - the most generic result form.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text</table><chair/><table>abc</table></root>"
                                                .getBytes());
                XPath oXPath0 = XPath.getXPathInstance("string(//root/table)");
                XPathResult res = oXPath0.evaluate(iXml);
                assertEquals(XPathResult.XPATH_STRING, res.getType());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • evaluate

        public XPathResult evaluate(long iResultNode)
        Evaluates the Xpath expression to the most generic result form XPathResult taking ResultNode handle as the input.
        Parameters:
        iNode - The ResultNode.
        Returns:
        Result as a XPathResult object - the most generic result form.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text<chair/></table></root>".getBytes());
                XPath oXPath0 = XPath.getXPathInstance("//root/table");
                NodeSet oNodeset = oXPath0.selectNodeSet(iXml);
                long iResNode = oNodeset.next();
                oXPath0 = XPath.getXPathInstance("string(//table/chair)");
                XPathResult res = oXPath0.evaluate(iResNode);
                assertEquals(XPathResult.XPATH_STRING, res.getType());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • evaluate

        public XPathResult evaluate(int iNode,
                                    XPathMetaInfo oMeta)
        Evaluates the Xpath expression to the most generic result form XPathResult.
        Parameters:
        iNode - The NOM integer
        oMeta - XPathMetaInfo object.
        Returns:
        Result as a XPathResult object - the most generic result form.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPath oXPath0 = XPath.getXPathInstance("string(//root/html4:table)");
                XPathResult res = oXPath0.evaluate(iXml,meta);
                assertEquals(XPathResult.XPATH_STRING, res.getType());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • evaluate

        public XPathResult evaluate(long iResultNode,
                                    XPathMetaInfo oMeta)
        Evaluates the Xpath expression to the most generic result form XPathResult.
        Parameters:
        iResultNode - The ResultNode
        oMeta - XPathMetaInfo object.
        Returns:
        Result as a XPathResult object - the most generic result form.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table>text</h:table><chair/></root>"
                                                .getBytes());
         
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                XPath oXPath0 = XPath.getXPathInstance("//html4:table");
                NodeSet oNodeset = oXPath0.selectNodeSet(iXml, meta);
         
                Long iResultNode = oNodeset.next();
                XPathResult oResult = oXPath0.evaluate(iResultNode, meta);
                System.out.println(oResult.getType());
                assertTrue(oResult.getType() == XPathResult.XPATH_NODESET);
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • evaluate

        public XPathResult evaluate(XPathMetaInfo oMeta)
        Evaluates the XPath expression to the most generic result form XPathResult taking MetaInfo as input.
        Parameters:
        oMeta - MetaInfo Object.
        Returns:
        XPathResult object as a result. null if MetaInfo is null

        Example:
         <code>
         XPathMetaInfo oMeta = new XPathMetaInfo();
         XPathResult xRes = XPathResult.getInstance(90);
         XPath oXPath = XPath.getXPathInstance("$var + $var");
         oMeta.addVarBinding("var", xRes);
         XPathResult xresult = oXPath.evaluate(oMeta);
         </code>
         
      • evaluateWithContext

        public XPathResult evaluateWithContext(int node,
                                               javax.xml.xpath.XPath customContext)
        Evaluate the expression based on the context specified.
        Parameters:
        node - - The NOM node to be searched up on.
        customContext - - The context to find the namespace, variable and function bindings.
        Returns:
        the result of XPath evaluation.
      • selectElementNodes

        public int[] selectElementNodes(int iNode)
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        array of integers that represent NOM Handles.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text</table><chair/></root>".getBytes());
         
                XPath oXPath0 = XPath.getXPathInstance("//root/*");
                int res[] = oXPath0.selectElementNodes(iXml);
                assertEquals("chair", Node.getName(res[1]));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • selectAttributeValues

        public java.lang.String[] selectAttributeValues(int iNode)
        Parameters:
        iNode - The NOM Handle to the input XML
        Returns:
        array of Strings that are the values of the attributes selected by the XPath expression

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table attr1=\"abc\">text</table><chair attr1=\"xyz\"/></root>"
                                                .getBytes());
         
                XPath oXPath0 = XPath.getXPathInstance("//@attr1");
                String strArr[] = oXPath0.selectAttributeValues(iXml);
                assertEquals("abc", strArr[0]);
                assertEquals("xyz", strArr[1]);
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • selectElementNodes

        public int[] selectElementNodes(int iNode,
                                        XPathMetaInfo metaInfo)
        Parameters:
        iNode - The NOM Handle to the input XML
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        Returns:
        array of integers that represent NOM Handles.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table>text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                XPath oXPath0 = XPath.getXPathInstance("//root/html4:table");
                int res[] = oXPath0.selectElementNodes(iXml, meta);
                assertEquals("h:table", Node.getName(res[0]));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • selectAttributeValues

        public java.lang.String[] selectAttributeValues(int iNode,
                                                        XPathMetaInfo metaInfo)
        Parameters:
        iNode - The NOM Handle to the input XML
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        Returns:
        array of Strings that are the values of the attributes selected by the XPath expression

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                XPath oXPath0 = XPath.getXPathInstance("//root/html4:table/@attr1");
                String strArr[] = oXPath0.selectAttributeValues(iXml, meta);
                assertEquals("abc", strArr[0]);
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • firstMatch

        public int firstMatch(int iNode,
                              XPathMetaInfo metaInfo)
        Parameters:
        iNode - The NOM Handle to the input XML
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        Returns:
        The first node which matches the pattern. If selected node is an attribute, then parent node will be returned

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                XPath oXPath0 = XPath.getXPathInstance("//root/html4:table/@attr1");
                int res = oXPath0.firstMatch(iXml, meta);
                assertEquals("h:table", Node.getName(res));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • firstMatchWithCustomContext

        public long firstMatchWithCustomContext(int iNode,
                                                javax.xml.xpath.XPath customContext)
        Select the first node which matches the give pattern. The returned ResultNode handle may represent an attribute also
        Parameters:
        iNode - - The NOM node
        customContext - - The Custom context
        Returns:
        Returns a long value that represents an XPath ResultNode handle.
      • getLocationStepsInExp

        @Deprecated
        public java.util.Vector getLocationStepsInExp()
        Deprecated. 
        This method will return the primary location step expressions in this XPath expression.Consider the XPath expression "//root/table or //root/furniture". In this expression there are two separate sub expressions combined by the operator 'or'.So this method will give the two sub-expressions wrapped in vector.


        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text</table><chair/><table>abc</table></root>"
                                                .getBytes());
                XPath oXPath0 = XPath.getXPathInstance("//root/table or //root/furniture");
                Vector res = oXPath0.getLocationStepsInExp();
                assertEquals(2, res.size());
                assertEquals("/descendant-or-self::node( )/child::root/child::table",
                                res.get(0).toString());
                assertEquals("/descendant-or-self::node( )/child::root/child::furniture",
                                res.get(1).toString());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • getLocationSteps

        public java.util.List<java.lang.String> getLocationSteps()
        Returns:
        list of sub-expressions. This method will return the primary location step expressions in this XPath expression.Consider the XPath expression "//root/table or //root/furniture". In this expression there are two separate sub expressions combined by the operator 'or'.So this method will give the list containing the sub expressions.


        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table>text</table><chair/><table>abc</table></root>"
                                                .getBytes());
                XPath oXPath0 = XPath.getXPathInstance("//root/table or //root/furniture");
                List<String> res = oXPath0.getLocationSteps();
                assertEquals(2, res.size());
                assertEquals("/descendant-or-self::node( )/child::root/child::table",
                                res.get(0));
                assertEquals("/descendant-or-self::node( )/child::root/child::furniture",
                                res.get(1));
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • delete

        public void delete()
      • getFirstMatch

        public static int getFirstMatch(java.lang.String exp,
                                        XPathMetaInfo metaInfo,
                                        int node)
        It returns the first node which matches the pattern. If selected node is an attribute, then parent node will be returned
        Parameters:
        exp - XPath expression to be evaluated
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        node - The NOM Handle to the input XML
        Returns:
        The first node which matches the pattern. If selected node is an attribute, then parent node will be returned

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                int res = XPath.getFirstMatch("//root/html4:table/@attr1", meta, iXml);
                assertEquals("h:table", Node.getName(res));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • getMatchingNodes

        public static int[] getMatchingNodes(java.lang.String exp,
                                             XPathMetaInfo metaInfo,
                                             int node)
        It returns Array of node which matches the pattern. If selected node is an attribute, then parent node will be returned
        Parameters:
        exp - XPath expression to be evaluated
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        node - The NOM Handle to the input XML
        Returns:
        Array of node which matches the pattern. If selected node is an attribute, then parent node will be returned

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                int res[] = XPath.getMatchingNodes("//root/html4:table", meta, iXml);
                assertEquals("h:table", Node.getName(res[0]));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • getMatchingNodeSet

        public static NodeSet getMatchingNodeSet(java.lang.String exp,
                                                 XPathMetaInfo metaInfo,
                                                 int node)
        It returns the matching NodeSet.
        Parameters:
        exp - XPath expression to be evaluated
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        node - The NOM Handle to the input XML
        Returns:
        Nodeset object.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                NodeSet res = XPath.getMatchingNodeSet("//root/html4:table", meta, iXml);
                long iResultNode = res.next();
                assertEquals("h:table", ResultNode.getName(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • evaluateExpression

        public static XPathResult evaluateExpression(java.lang.String exp,
                                                     XPathMetaInfo metaInfo,
                                                     int node)
        It evaluates the XPath expression and returns the XPathResult object.
        Parameters:
        exp - XPath expression to be evaluated
        metaInfo - MetaInfo to be passed for namespace or attribute bindings
        node - The NOM Handle to the input XML
        Returns:
        XPathResult object


        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root xmlns:h=\"http://www.w3.org/TR/html4\" ><h:table attr1=\"abc\">text</h:table><chair/></root>"
                                                .getBytes());
                XPathMetaInfo meta = new XPathMetaInfo();
                meta.addNamespaceBinding("html4", "http://www.w3.org/TR/html4");
                XPathResult res = XPath
                                .evaluateExpression("//root/html4:table", meta, iXml);
                assertEquals(XPathResult.XPATH_NODESET, res.getType());
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         </code>
         
      • getSourceExpression

        public java.lang.String getSourceExpression()
        It returns the XPath Expression for the given XPath object.
        Returns:
        The expression from which the object is made

        Example:
         <code>
         XPath oXPath0 = XPath.getXPathInstance("//root/html4:table");
         assertEquals("//root/html4:table", oXPath0.getSourceExpression());
         </code>
         
      • getTotalXPathObjects

        public static int getTotalXPathObjects()
        Returns the total number of XPath objects created
        Returns:
        the total number of XPath objects.

        Example:
         <code>
         Path.getTotalXPathObjects();
         </code>
         
      • getTotalXPathExpressionObjects

        public static int getTotalXPathExpressionObjects()
        Returns the total number of XPath expression objects created
        Returns:
        the total number of XPath expression objects.

        Example:
         <code>
         Path.getTotalXPathExpressionObjects();
         </code>
         
      • getNativeHandle

        protected long getNativeHandle()