public class SaxParser<CI,RI>
extends java.lang.Object
SaxParser scans a XML stream and compares it to a search pattern.
A pattern is wrapped in a SaxParser.Context and matches if XML depth and XML tag name of stream is arrived. In this case a "SaxParser.Record" object is created. It can be either:SaxParser process more than one patterns as "OR" and nested patterns as "AND". Nested patterns implicate children, top levels parents.
Its a good practice to define exactly one parent and zero or more children per scan. The less children is defined, the less memory is used. Max allowed xml depth is Long.BYTES*8.
A pattern can either match by tag name (Syntax: "tagName") or tag name and attribute value (Syntax: "tagName#attribName=value") what gives it a stricter fine search. Each xml depth is separated by "/". An Example can be found in linking schema specifications under <target>
Note: This Class has no depencies to other classes and contains a Main() testMethod
This source is free; you can redistribute it and/or modify it under the terms of the GNU General Public License and by nameing of the originally author
| Modifier and Type | Class and Description |
|---|---|
static class |
SaxParser.Context<CI,RI>
A helper class
a) to cache callbacks from SaxParser
b) to define a certain tag in a certain xml tree
to be found and
c) additional infos what to do next with that Record
|
static class |
SaxParser.Record<CI,RI>
A wrapper that contains xml tag datas
|
(package private) static interface |
SaxParser.RecordHandler<CI,RI> |
private static class |
SaxParser.SaxHandler<CI,RI> |
| Modifier and Type | Field and Description |
|---|---|
private SaxParser.RecordHandler<CI,RI> |
handler |
| Modifier | Constructor and Description |
|---|---|
private |
SaxParser() |
|
SaxParser(SaxParser.RecordHandler<CI,RI> handler)
handler is a callback (see interface descriptions)
|
| Modifier and Type | Method and Description |
|---|---|
static <CI,RI> SaxParser.Context<CI,RI> |
createSearchContext(java.lang.String xmlSearchPattern,
SaxParser.Context<CI,RI> parent)
Creates a search context containing search pattern
If context is nested then add parent context
|
void |
parse(SaxParser.Context<CI,RI>[] params,
java.lang.String filename)
Starts xml scan
|
private SaxParser.RecordHandler<CI,RI> handler
private SaxParser()
public SaxParser(SaxParser.RecordHandler<CI,RI> handler)
handler - mustn't be nullpublic void parse(SaxParser.Context<CI,RI>[] params, java.lang.String filename) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
params - , created with createSearchContext()filename - (absolute Path)javax.xml.parsers.ParserConfigurationExceptionorg.xml.sax.SAXExceptionjava.io.IOExceptionpublic static <CI,RI> SaxParser.Context<CI,RI> createSearchContext(java.lang.String xmlSearchPattern, SaxParser.Context<CI,RI> parent)
xmlSearchPattern - i.e. "rootDoc/tags/tag/subtag" or "rootDoc/tags/tag/subtag#attribName=value"parent - or null if it's the first parent context