public class XPathMetaInfo
extends java.lang.Object
Constructor and Description |
---|
XPathMetaInfo()
Creates an instance of XPathMetaInfo object.
|
Modifier and Type | Method and Description |
---|---|
void |
addNamespaceBinding(java.lang.String sPrefix,
java.lang.String sURI)
Binds a prefix to the specific URI in the document.
|
void |
addVarBinding(java.lang.String sVarName,
XPathResult oXpathResult)
Binds a result to a variable.
|
void |
delete()
Deletes native handle of the XPathMetaInfo object explicitly.
|
protected void |
finalize() |
java.lang.String |
getNamespaceBinding(java.lang.String sPrefix) |
protected long |
getNativeHandle() |
void |
registerIDAttribute(java.lang.String sAttr)
Registers an ID Attribute.This refers to an attribute that will have
unique value in the document.That is, no two elements in the document can
have the same unique id.
|
public XPathMetaInfo()
IllegalOperationException
in case of any error.public void registerIDAttribute(java.lang.String sAttr)
sAttr
- The attribute that is to be registered.
<code> Document oDocument = new Document(); int iXml; try { iXml = oDocument .load("<root><table attr=\"abc\">text1</table><table attr=\"xyz\">text2</table></root>" .getBytes()); XPathMetaInfo m = new XPathMetaInfo(); m.registerIDAttribute("attr"); String str1 = "\"abc\""; XPath x = XPath.getXPathInstance("id(" + str1 + ")"); XPathResult xRes = x.evaluate(iXml, m); NodeSet n = xRes.removeNodeSetFromResult(); int res[] = n.getElementNodes(); assertEquals("<table attr=\"abc\">text1</table>", Node.writeToString( res[0], false)); str1 = "\"xyz\""; x = XPath.getXPathInstance("id(" + str1 + ")"); xRes = x.evaluate(iXml, m); n = xRes.removeNodeSetFromResult(); res = n.getElementNodes(); assertEquals("<table attr=\"xyz\">text2</table>", Node.writeToString( res[0], false)); } catch (XMLException e) { e.printStackTrace(); } </code>
public void addVarBinding(java.lang.String sVarName, XPathResult oXpathResult)
sVarName
- Variable to be bound. eg: var => $var is boundoXpathResult
- The XPathResult object <code> Document doc = new Document(); int iXml; try { iXml = doc .load("<root><table attr=\"abc\">text</table><chair attr=\"abc\"/></root>" .getBytes()); XPathMetaInfo m = new XPathMetaInfo(); XPathResult xRes = XPathResult.getInstance("abc"); XPath x = XPath.getXPathInstance("//root/*[@attr=$var]"); m.addVarBinding("var", xRes); XPathResult xResult = x.evaluate(iXml, m); NodeSet nSet = xResult.removeNodeSetFromResult(); assertEquals(2, nSet.size()); } catch (XMLException e) { e.printStackTrace(); } </code>
public void addNamespaceBinding(java.lang.String sPrefix, java.lang.String sURI)
sPrefix
- - prefix stringsURI
- - URI to be bound
<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); assertEquals(XPathResult.XPATH_STRING, res.getType()); } catch (XMLException e) { e.printStackTrace(); } </code>
public java.lang.String getNamespaceBinding(java.lang.String sPrefix)
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void delete()
<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); assertEquals(XPathResult.XPATH_STRING, res.getType()); meta.delete(); } catch (XMLException e) { e.printStackTrace(); } </code>
protected long getNativeHandle()