public class XPathResult
extends java.lang.Object
Document doc = new Document();
int iXml = doc.load("Book.xml");
XPath oXPath = new XPath("/book/chapter[1]/lesson[1]/child::text()");
//Return as a generic XPathResult.
XPathResult oXPathResult = oXPath.evaluate(iXml);
| Modifier and Type | Field and Description |
|---|---|
static int |
XPATH_BOOLEAN
XPATH_BOOLEAN represents that the XPathResult is of type
boolean. |
static int |
XPATH_CUSTOM
XPATH_CUSTOM represents that the XPathResult is user
defined. |
static int |
XPATH_INVALID
XPATH_INVALID represents that the XPathResult is of invalid
type. |
static int |
XPATH_NaN
XPATH_NaN represents that the XPathResult is of NaN type. |
static int |
XPATH_NODESET
XPATH_NODESET represents that the XPathResult is of type
NodeSet. |
static int |
XPATH_NUMBER
XPATH_NUMBER represents that the XPathResult is of type
'number' - double. |
static int |
XPATH_STRING
XPATH_STRING represents that the XPathResult is of type
String. |
| Modifier | Constructor and Description |
|---|---|
protected |
XPathResult()
Private constructor.
|
protected |
XPathResult(long iHandle) |
protected |
XPathResult(long iHandle,
int type) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
delete()
This method deletes the XPathResult Object.
|
protected void |
finalize() |
boolean |
getBooleanResult()
If the type is XPATH_BOOLEAN the result is returned as a
boolean. |
java.lang.Object |
getCustomResultObject()
If the type is XPATH_CUSTOM the result is returned as an
Object. |
static XPathResult |
getInstance(boolean b)
Returns a new XPathResult object with the result type
XPATH_BOOLEAN . |
static XPathResult |
getInstance(double d)
Returns a new XPathResult object with the result type
XPATH_NUMBER |
static XPathResult |
getInstance(NodeSet oNSet)
Returns a new XPathResult object with the result type
XPATH_NODESET |
static XPathResult |
getInstance(java.lang.Object o)
Returns a new XPathResult object with the result type
XPATH_CUSTOm |
static XPathResult |
getInstance(java.lang.String str)
Returns a new XPathResult object with the result type
XPATH_STRING |
double |
getNumberResult()
If the type is XPATH_NUMBER the result is returned as a
double. |
java.lang.String |
getStringResult()
If the type is XPATH_STRING the result is returned as a
String. |
int |
getType()
Returns the type of result this object represents.
|
NodeSet |
removeNodeSetFromResult()
If the type is XPATH_NODESET the result is returned as a
NodeSet. |
void |
setResult(boolean b)
It sets the type of XPathResult object to XPATH_BOOLEAN.
|
void |
setResult(double d)
It sets the type of XPathResult object to XPATH_NUMBER.
|
void |
setResult(NodeSet n)
It sets the type of XPathResult object to XPATH_NODESET.
|
void |
setResult(java.lang.Object b)
It sets the type of XPathResult object to XPATH_CUSTOM.
|
void |
setResult(java.lang.String s)
It sets the type of XPathResult object to XPATH_STRING.
|
java.lang.String |
toString()
This function converts the native result handle to string.
|
public static final int XPATH_BOOLEAN
XPATH_BOOLEAN represents that the XPathResult is of type
boolean.public static final int XPATH_NODESET
XPATH_NODESET represents that the XPathResult is of type
NodeSet.public static final int XPATH_STRING
XPATH_STRING represents that the XPathResult is of type
String.public static final int XPATH_NUMBER
XPATH_NUMBER represents that the XPathResult is of type
'number' - double.public static final int XPATH_CUSTOM
XPATH_CUSTOM represents that the XPathResult is user
defined.public static final int XPATH_NaN
XPATH_NaN represents that the XPathResult is of NaN type.public static final int XPATH_INVALID
XPATH_INVALID represents that the XPathResult is of invalid
type.protected XPathResult()
protected XPathResult(long iHandle)
protected XPathResult(long iHandle,
int type)
public static XPathResult getInstance(java.lang.String str)
XPATH_STRING str - The result input string.
<code>
XPathResult res = XPathResult.getInstance("BPM");
assertEquals(XPathResult.XPATH_STRING, res.getType());
</code>
public static XPathResult getInstance(double d)
XPATH_NUMBER d - The result input number.<code> XPathResult res = XPathResult.getInstance(10.5); assertEquals(XPathResult.XPATH_NUMBER, res.getType()); </code>
public static XPathResult getInstance(boolean b)
XPATH_BOOLEAN .b - The boolean input result.<code> XPathResult res = XPathResult.getInstance(true); assertEquals(XPathResult.XPATH_BOOLEAN, res.getType()); </code>
public static XPathResult getInstance(NodeSet oNSet)
XPATH_NODESET oNSet - The NodeSet object as result input.
<code>
Document oDocument = new Document();
int iNode;
try {
iNode = oDocument.load("<root><table>text</table><chair/></root>"
.getBytes());
XPath oXPath0 = XPath.getXPathInstance("//root/table");
XPathResult res = oXPath0.evaluate(iNode);
NodeSet nSet = res.removeNodeSetFromResult();
XPathResult res2 = XPathResult.getInstance(nSet);
assertEquals(XPathResult.XPATH_NODESET, res2.getType());
} catch (XMLException e) {
e.printStackTrace();
}
</code>
public static XPathResult getInstance(java.lang.Object o)
XPATH_CUSTOm o - The object as result input.<code> String str = "abc"; XPathResult res = XPathResult.getInstance((Object) str); assertEquals(XPathResult.XPATH_CUSTOM, res.getType()); </code>
public int getType()
XPATH_NUMBER,XPATH_NODESET,XPATH_BOOLEAN,XPATH_STRING .<code> String str = "abc"; XPathResult res = XPathResult.getInstance((Object) str); assertEquals(XPathResult.XPATH_CUSTOM, res.getType()); </code>
protected void delete()
<code> String str = "abc"; XPathResult res = XPathResult.getInstance((Object) str); res.delete(); </code>
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwablepublic java.lang.String getStringResult()
String. Else InvalidFormatException is thrown
<code>
Document oDocument = new Document();
int iNode;
try {
String str = "\"abc \"";
iNode = oDocument.load("<root><table>text</table><chair/></root>"
.getBytes());//Trims the leading and trailing space from string. Also replaces consecutive occurrences of white space with a single space.
XPath oXPath0 = XPath.getXPathInstance("normalize-space(" + str + ")");
XPathResult res = oXPath0.evaluate(iNode);
assertEquals(XPathResult.XPATH_STRING, res.getType());
assertEquals("abc", res.getStringResult());
} catch (XMLException e) {
e.printStackTrace();
}
</code>
public boolean getBooleanResult()
boolean. Else InvalidFormatException is thrown
<code>
Document oDocument = new Document();
int iNode;
try {
String str1 = "\"landscape\"";
String str2 = "\"sky\"";
iNode = oDocument.load("<root><table>text</table><chair/></root>"
.getBytes());
XPath oXPath0 = XPath.getXPathInstance("contains(" + str1 + "," + str2
+ ")");//Returns true if the first string contains the second string.
XPathResult res = oXPath0.evaluate(iNode);
assertEquals(false, res.getBooleanResult());
} catch (XMLException e) {
e.printStackTrace();
}
</code>
public double getNumberResult()
double. Else InvalidFormatException is thrown
<code>
Document oDocument = new Document();
int iNode;
try {
iNode = oDocument.load("<root><table>text</table><chair/></root>"
.getBytes());
XPath oXPath0 = XPath.getXPathInstance("5+3");//Returns true if the first string contains the second string.
XPathResult res = oXPath0.evaluate(iNode);
assertEquals(8.0, res.getNumberResult());
} catch (XMLException e) {
e.printStackTrace();
}
</code>
public NodeSet removeNodeSetFromResult()
NodeSet. Else InvalidFormatException is thrown.
The native XPathResult is cleared.
<code>
Document oDocument = new Document();
int iNode;
try {
iNode = oDocument.load("<root><table>text</table><chair/></root>".getBytes());
XPath oXPath0 = XPath.getXPathInstance("//root/table");//Returns true if the first string contains the second string.
XPathResult res = oXPath0.evaluate(iNode);
NodeSet nSet = res.removeNodeSetFromResult();
}
long iRes = nSet.next();
assertEquals("table",ResultNode.getName(iRes));
} catch (XMLException e) {
e.printStackTrace();
</code>
public java.lang.Object getCustomResultObject()
Object. Else InvalidFormatException is thrown<code> XPathResult result = XPathResult.getInstance((Object)"xml"); assertEquals(XPathResult.XPATH_CUSTOM, result.getType()); Object object = result.getCustomResultObject(); </code>
public void setResult(double d)
d - The double value to be set.
<code> XPathResult res = XPathResult.getInstance(10.5); assertEquals(XPathResult.XPATH_NUMBER, res.getType()); res.setResult(true); assertEquals(XPathResult.XPATH_BOOLEAN, res.getType()); </code>
public void setResult(NodeSet n)
n - The nodeSet to be set.
<code>
try {
iNode = oDocument.load("<root><table>text</table><chair/></root>"
.getBytes());
XPath oXPath0 = XPath.getXPathInstance("//root/table");
XPathResult res = oXPath0.evaluate(iNode);
NodeSet nSet = res.removeNodeSetFromResult();
XPathResult res2 = XPathResult.getInstance(10.5);
assertEquals(XPathResult.XPATH_NUMBER, res2.getType());
res2.setResult(nSet);
assertEquals(XPathResult.XPATH_NODESET, res2.getType());
} catch (XMLException e) {
e.printStackTrace();
}
</code>
public void setResult(java.lang.String s)
s - The string value to be set.
<code>
XPathResult res = XPathResult.getInstance(true);
assertEquals(XPathResult.XPATH_BOOLEAN, res.getType());
res.setResult("Cordys BCP");
assertEquals(XPathResult.XPATH_STRING, res.getType());
</code>
public void setResult(boolean b)
b - The boolean value to be set.
<code> XPathResult res = XPathResult.getInstance(10.5); assertEquals(XPathResult.XPATH_NUMBER, res.getType()); res.setResult(true); assertEquals(XPathResult.XPATH_BOOLEAN, res.getType()); </code>
public void setResult(java.lang.Object b)
b - The Object to be set.
<code> String str = "xml"; XPathResult res = XPathResult.getInstance(10.5); assertEquals(XPathResult.XPATH_NUMBER, res.getType()); res.setResult((Object) str); assertEquals(XPathResult.XPATH_CUSTOM, res.getType()); </code>
public java.lang.String toString()
toString in class java.lang.Object