Skip navigation links
com.eibus.xml.xpath

Class ResultNode

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int ATTRIBUTE 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static int getElementNode(long iResultNode)
      This method returns the NOM node handle as an integer taking the input as a ResultNode.If it is an attribute, the parent NOM Node is returned.
      static java.lang.String getLocalName(long iRes)
      Returns the local name of element/attribute that the ResultNode represents.
      static java.lang.String getName(long iRes)
      Returns the qualified name of element/attribute that the ResultNode represents.
      static java.lang.String getNamespaceURI(long iRes)
      Returns the namespace uri associated with the element/attribute that the ResultNode represents.
      static java.lang.String getPrefix(long iRes)
      Returns the prefix of element/attribute that the ResultNode represents.
      static java.lang.String getStringValue(long iRes)
      Returns a string value of the ResultNode handle, if it represents an 'attribute'.
      static boolean isAttribute(long iRes)
      Returns true if the input ResultNode represents an attribute of type ResultNode.ATTRIBUTE
      static boolean isElement(long iRes)
      Returns true if the input ResultNode represents an element of type NodeType.ELEMENT
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getStringValue

        public static java.lang.String getStringValue(long iRes)
        Returns a string value of the ResultNode handle, if it represents an 'attribute'.
        Parameters:
        iRes - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        The String value of the attribute.

        Example:
        
         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/@attr1", null, iXml);
                long iResultNode = res.next();
                String attr = ResultNode.getStringValue(iResultNode);
                assertEquals("abc", attr);
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         
      • isAttribute

        public static boolean isAttribute(long iRes)
        Returns true if the input ResultNode represents an attribute of type ResultNode.ATTRIBUTE
        Parameters:
        iRes - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        boolean true/false if the input integer handle refers to an NOM Attribute

        Example:
        
         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/@attr1", null, iXml);
                long iResultNode = res.next();
                assertEquals(true, ResultNode.isAttribute(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
      • isElement

        public static boolean isElement(long iRes)
        Returns true if the input ResultNode represents an element of type NodeType.ELEMENT
        Parameters:
        iRes - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        true if the result node represents NodeType.ELEMENT

        Example:
        
         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);
                long iResultNode = res.next();
                assertEquals(true, ResultNode.isElement(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         
      • getElementNode

        public static int getElementNode(long iResultNode)
        This method returns the NOM node handle as an integer taking the input as a ResultNode.If it is an attribute, the parent NOM Node is returned. <name type = "x"/> => If the ResultNode refers to "name",then the nom node associated with it is returned. If the input ResultNode refers to attribute 'type', still the nom node associated to "name" element is returned.
        Parameters:
        iResultNode - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        The NOM Node associated with this ResultNode

        Example:
        
         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);
                long iResultNode = res.next();
                int ele = ResultNode.getElementNode(iResultNode);
                assertEquals("table", Node.getName(ele));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
      • getName

        public static java.lang.String getName(long iRes)
        Returns the qualified name of element/attribute that the ResultNode represents. Example:
        Consider the xml "<prefix:name prefix:id = "1" prefix:type = "x"/>".
        if the ResultNode refers to "name", the string "prefix:name" will be returned.
        If the ResultNode refers to the attribute "type", the string "prefix:type" will be returned.
        Parameters:
        iRes - The ResultNode ie. an integer of type XPath.XPATH_RESULTNODE
        Returns:
        returns the qualified name of the node.

        Example:
        
         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);
                long iResultNode = res.next();
                assertEquals("table", ResultNode.getName(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
      • getLocalName

        public static java.lang.String getLocalName(long iRes)
        Returns the local name of element/attribute that the ResultNode represents. Example:
        Consider the xml "<prefix:name prefix:id = "1" prefix:type = "x"/>".
        if the ResultNode refers to "name", the string "name" will be returned.
        If the ResultNode refers to the attribute "type", the string "type" will be returned.
        Parameters:
        iRes - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        returns the local name of the node.

        Example:
        
         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 = res.next();
                assertEquals("table", ResultNode.getLocalName(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         
      • getPrefix

        public static java.lang.String getPrefix(long iRes)
        Returns the prefix of element/attribute that the ResultNode represents. Example:
        Consider the xml "<prefix1:name prefix1:id="1" prefix2:type="x" xmlns:prefix1="http://prefix1" xmlns:prefix2="http://prefix2" />".
        if the ResultNode refers to "name", the string "prefix1" will be returned.
        If the ResultNode refers to the attribute "type", the string "prefix2" will be returned.
        Parameters:
        iRes - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        returns the prefix name of the node or attribute.

        Example:
        
         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 = res.next();
                assertEquals("h", ResultNode.getPrefix(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }
         
         
      • getNamespaceURI

        public static java.lang.String getNamespaceURI(long iRes)
        Returns the namespace uri associated with the element/attribute that the ResultNode represents. Example:
        Consider the xml "<prefix1:name prefix1:id="1" prefix2:type="x" xmlns:prefix1="http://prefix1" xmlns:prefix2="http://prefix2" />".
        if the ResultNode refers to "name", then "http://prefix1" will be returned.
        If the ResultNode refers to the attribute "type", then "http://prefix2" will be returned.
        Parameters:
        iRes - The ResultNode(long value representing the type XPath.XPATH_RESULTNODE)
        Returns:
        returns the prefix name of the node or attribute.

        Example:
        
         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 = res.next();
                assertEquals("http://www.w3.org/TR/html4", ResultNode.getNamespaceURI(iResultNode));
         
         } catch (XMLException e) {
                e.printStackTrace();
         }