public class XPathReader
extends java.lang.Object
XPath
on a file/URI without actually parsing the complete source XML.
With this, we first intialize the XPathReader
with the filename or URI and XPath
object.
After initializing the XPathReader
, we can use methods to get the next matched element.
The parsing of XML will take place after identifying the exact matching element and it will parse only the next matched content only.
Document oDocument = new Document();
String fileName = "BookStore.xml";
XPathMetaInfo oMeta = new XPathMetaInfo();
oMeta.addNamespaceBinding("cordys", "http://schemas.cordys.com/bookstore");
XPath oXPath = new XPath("/cordys:book/chapter/lesson");
XPathReader oXPathReader = XPathReader.getXPathReader(oXPath, oMeta, oDocument, fileName);
//If the reader is to be created from an InputStream object, use :
//XPathReader oXPathReader = XPathReader.getXPathReaderFromStream(oXPath, oXPathMetaInfo, oDocument, inputStream);
oXPathReader.open();
int node = oXPathReader.loadNextNode();
while (nods != 0)
{
// process node
//Call 'getNextMatchInLoadedNode()' for finding any further matching node in the loaded node.
//'getNextMatchInLoadedNode()' can potentially select nodes, if the search pattern
// contains descendant or descendant-or-self axes.
Node.delete(node);
node = oXPathReader.loadNextNode();
}
oXPathReader.close();
Modifier and Type | Method and Description |
---|---|
boolean |
close()
Closes the XPathReader.
|
NodeSet |
getNextMatch()
Deprecated.
, please use 'loadNextNode' and 'getNextMatchInLoadedNode'
|
int |
getNextMatchInLoadedNode()
Return the next matching node in the loaded NOM tree returned by
loadNextNode() method. |
int |
getNextNode()
Deprecated.
, please use 'loadNextNode' and 'getNextMatchInLoadedNode'
|
ResourceOwner |
getResourceOwner()
Deprecated.
|
static XPathReader |
getXPathReader(XPath xpath,
XPathMetaInfo meta,
Document doc,
java.lang.String uri)
Creates the
XPathReader instance for URI. |
static XPathReader |
getXPathReaderFromStream(XPath xpath,
XPathMetaInfo meta,
Document doc,
java.io.InputStream input)
Creates the
XPathReader instance for the InputStream |
int |
loadNextNode()
Loads the next NOM node from the stream.
|
boolean |
open()
Opens the XPathReader for processing.
|
public ResourceOwner getResourceOwner()
public static XPathReader getXPathReader(XPath xpath, XPathMetaInfo meta, Document doc, java.lang.String uri)
XPathReader
instance for URI.xpath
- The XPath object for identifying the patternmeta
- The XPath meta informationdoc
- The NOM Document required for parsing the target/selected XML contenturi
- The source xml locationXPathReader
instance or null if the input data is invalid.public static XPathReader getXPathReaderFromStream(XPath xpath, XPathMetaInfo meta, Document doc, java.io.InputStream input)
XPathReader
instance for the InputStream
xpath
- The XPath object for identifying the patternmeta
- The XPath meta informationdoc
- The NOM Document required for parsing the target/selected XML contentinputStream
- The InputStream
object representing the source xml.XPathReader
instance or null if the input data is invalid.public boolean open()
public NodeSet getNextMatch()
NodeSet
public int getNextNode()
public boolean close()
public int loadNextNode()
getNextMatchInLoadedNode()
public int getNextMatchInLoadedNode()
loadNextNode()
method.