Skip navigation links
com.eibus.xml.xpath

Class NodeSet

    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected NodeSet(long iHandle)
      This constructor will be used by the XPathResult class native method
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void delete()
      Deletes the native NodeSet handle.
      protected void finalize() 
      int[] getAttributeNodes()
      This function returns the array of Element Nodes(NOM integer) corresponding to attributes present in the Nodeset object.
      java.lang.String[] getAttributeValues()
      This function returns the array of strings which are the values of the attributes present in the Nodeset object.
      int[] getElementNodes()
      This function returns the array of Element Nodes that the Nodeset object contains.
      long getNativeHandle()
      This function returns the Native handle of this object.
      boolean hasNext()
      Returns false if the NodeSet is empty, true otherwise.
      long next()
      Returns a long value that represents an XPath ResultNode handle.
      void show()
      Displays the nodes present in the NodeSet.
      int size()
      Returns the number of ResultNodes in the Nodeset.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NodeSet

        protected NodeSet(long iHandle)
        This constructor will be used by the XPathResult class native method
        Parameters:
        iHandle - The native handle to the Nodeset.
    • Method Detail

      • hasNext

        public boolean hasNext()
        Returns false if the NodeSet is empty, true otherwise.
        Returns:
        boolean 'true'/'false'

        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());
                NodeSet res = XPath.getMatchingNodeSet("//root/html4:table", meta, iXml);
                long iResultNode = 0;
                if (res.hasNext()) {
                        iResultNode = res.next();
                }
                assertEquals("table", ResultNode.getLocalName(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • size

        public int size()
        Returns the number of ResultNodes in the Nodeset.
        Returns:
        Number of elements that are present in the NodeSet

        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());
                NodeSet res = XPath.getMatchingNodeSet("//root/html4:table", meta, iXml);
                assertEquals(1, res.size());
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • next

        public long next()
        Returns a long value that represents an XPath ResultNode handle.
        Returns:
        integer that represents an XPath ResultNode

        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());
                NodeSet res = XPath.getMatchingNodeSet("//root/html4:table", meta, iXml);
                long iResultNode = 0;
                iResultNode = res.next();
                assertEquals("table", ResultNode.getLocalName(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • show

        public void show()
        Displays the nodes present in the NodeSet.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table attr1=\"abc\">text</table><chair attr1=\"xyz\"/></root>"
                                                .getBytes());
                NodeSet res = XPath.getMatchingNodeSet("//root/table", null, iXml);
                res.show();//displays number of items and element names in console.
         } 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()
        Deletes the native NodeSet handle.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table attr1=\"abc\">text</table><chair attr1=\"xyz\"/></root>"
                                                .getBytes());
                NodeSet res = XPath.getMatchingNodeSet("//root/table", null, iXml);
                res.delete();
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • getElementNodes

        public int[] getElementNodes()
        This function returns the array of Element Nodes that the Nodeset object contains.
        Returns:
        The array of Element Nodes present in the Nodeset returned as NOM integers.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table attr1=\"abc\">text</table><chair attr1=\"xyz\"/></root>"
                                                .getBytes());
                NodeSet res = XPath.getMatchingNodeSet("//root/table", null, iXml);
                int eleArr[] = res.getElementNodes();
                assertEquals("table", Node.getName(eleArr[0]));
         } catch (XMLException e) {
                e.printStackTrace();
         }
         </code>
         
      • getAttributeValues

        public java.lang.String[] getAttributeValues()
        This function returns the array of strings which are the values of the attributes present in the Nodeset object.
        Returns:
        Array of strings that are the values of the resultant attributes.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table attr1=\"abc\">text</table><chair/></root>"
                                                .getBytes());
                NodeSet res = XPath.getMatchingNodeSet("//root/table/@attr1", null, iXml);
                String StrArr[] = res.getAttributeValues();
                assertEquals("abc", StrArr[0]);
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         </code>
         
      • getAttributeNodes

        public int[] getAttributeNodes()
        This function returns the array of Element Nodes(NOM integer) corresponding to attributes present in the Nodeset object.
        Returns:
        The array of Element Nodes(NOM integer) corresponding to resultant attributes.

        Example:
         <code>
         Document oDocument = new Document();
         int iXml;
         try {
                iXml = oDocument
                                .load("<root><table attr1=\"abc\">text</table><chair/></root>"
                                                .getBytes());
                NodeSet res = XPath.getMatchingNodeSet("//root/table/@attr1", null, iXml);
                int eleArr[] = res.getAttributeNodes();
                assertEquals("table", Node.getName(eleArr[0]));
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         </code>
         
      • getNativeHandle

        public long getNativeHandle()
        This function returns the Native handle of this object.
        Returns:
        The native handle of this object.