public final class ResultNode
extends java.lang.Object
long
values that are of type XPath ResultNode. Result Node contains the result
that can of type NodeType.ELEMENT or ResultNode.ATTRIBUTE
Document oDocument = new Document();
int iXml = oDocument.load("weather.xml");
XPath oXPath = XPath.getXPathInstance("//weather/forecast/node()");
NodeSet oNodeSet = oXPath.selectNodeSet(iXml);
//Iterate through the results
while (oNodeSet.hasNext())
{
long iResultNode= oNodeSet.next();//this is a handle to the XmlResultNode obj in the native layer
if (ResultNode.isAttribute(iResultNode)){
String s = ResultNode.getStringValue(iResultNode);
} else {
int iNode = ResultNode.getElementNode(iResultNode);
}
}
Modifier and Type | Field and Description |
---|---|
static int |
ATTRIBUTE |
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 |
public static final int ATTRIBUTE
public static java.lang.String getStringValue(long iRes)
iRes
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)
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();
}
public static boolean isAttribute(long iRes)
ResultNode.ATTRIBUTE
iRes
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)
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();
}
public static boolean isElement(long iRes)
NodeType.ELEMENT
iRes
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)NodeType.ELEMENT
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();
}
public static int getElementNode(long iResultNode)
<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.iResultNode
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)
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();
}
public static java.lang.String getName(long iRes)
iRes
- The ResultNode ie. an integer of type
XPath.XPATH_RESULTNODE
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();
}
public static java.lang.String getLocalName(long iRes)
iRes
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)
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();
}
public static java.lang.String getPrefix(long iRes)
iRes
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)
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();
}
public static java.lang.String getNamespaceURI(long iRes)
iRes
- The ResultNode(long value representing the type
XPath.XPATH_RESULTNODE
)
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();
}