| pnuts.xml.DigestHandler pnuts.xml.DigestReader
DigestReader | public class DigestReader extends DigestHandler (Code) | | DigestReader is used to retrieve useful information, for the application, from a XML document.
XML documents are processed based on user-defined 'rules', which consists of [Action, Path, Key].
- Action
- A DigestAction object, or the associated name of the action.
- Path
- Qualified Names separated by slash (/). Wildcard (*) can be used instead of actual names.
When Path starts with '//', it is used to match sub-elements.
(e.g., /a/b/c, /a/ * /c, //b/c, // *)
- Key
- the key to access the intermediate result. If omitted, the relative path to the
nearest ancestor node is implicitly defined.
Those rules can be defined with the setRules() method or addRule() method.
User can define the action names with setAlias() method, passing a Map of String->DigestAction.
One of parse() methods processes a XML document based on the rules.
An example:
import pnuts.xml.*;
import pnuts.xml.action.*;
DigestReader dr = new DigestReader();
DigestAction text = new TextAction();
DigestAction list = new ListAction();
DigestAction map = new MapAction();
Object[][] rules = {{text, "/rss/channel/title", "title"},
{text, "/rss/channel/link", "link"},
{text, "/rss/channel/description", "description"},
{list, "/rss/channel/item", "item"},
{text, "/rss/channel/item/title"},
{text, "/rss/channel/item/link"},
{text, "/rss/channel/item/description"}};
dr.setRules(rules);
Map doc = (Map)dr.parse(new FileInputStream("rss.xml"));
|
Inner Class :static class NullInputStream extends InputStream | |
DigestReader | public DigestReader()(Code) | | Constructor
|
DigestReader | public DigestReader(Object[][] defs)(Code) | | Constructor
Parameters: defs - the rules that consist of 'Action', 'Path', and optional 'Key'.- Action
- A DigestAction object, or the associated name of the action.
- Path
- A path identifier, which is a '/'-separated qualified names
- Key
- the key to access the intermediate result.
|
DigestReader | public DigestReader(SAXParser parser)(Code) | | Constructor
Parameters: parser - a SAX parser |
DigestReader | public DigestReader(SAXParser parser, Object[][] defs)(Code) | | Constructor
Parameters: parser - a SAX parser Parameters: defs - the rules that consist of 'Action', 'Path', and optional 'Key'.- Action
- A DigestAction object, or the associated name of the action.
- Path
- A path identifier, which is a '/'-separated qualified names
- Key
- the key to access the intermediate result.
|
getAliases | public Map getAliases()(Code) | | Retrieves the alias map
the alias map; ActionName -> DigestAction |
setAliases | public void setAliases(Map map)(Code) | | Defines the alias map; ActionName -> DigestAction
Parameters: map - the alias map |
setRules | public void setRules(Object[][] defs)(Code) | | Sets the rules
Parameters: defs - the rules that consist of 'Action', 'Path', and optional 'Key'.- Action
- A DigestAction object, or the associated name of the action.
- Path
- A path identifier, which is a '/'-separated qualified names
- Key
- the key to access the intermediate result.
|
Methods inherited from pnuts.xml.DigestHandler | public void addRule(DigestAction action, String path)(Code)(Java Doc) public void addRule(DigestAction action, String path, String keyword)(Code)(Java Doc) public void characters(char ch, int start, int length) throws org.xml.sax.SAXException(Code)(Java Doc) public Object currentListValue()(Code)(Java Doc) public void endElement(String uri, String localName, String qName) throws org.xml.sax.SAXException(Code)(Java Doc) String getKey(String path)(Code)(Java Doc) String getStackTopPath()(Code)(Java Doc) Object getStackTopValue()(Code)(Java Doc) public Object getValue()(Code)(Java Doc) void initialize()(Code)(Java Doc) public boolean isUseLocalNames()(Code)(Java Doc) public boolean listAlive(String path)(Code)(Java Doc) Object popValue()(Code)(Java Doc) void pushValue(String path, Object value)(Code)(Java Doc) public synchronized void registerListPath(String path, Object list)(Code)(Java Doc) static boolean sameBranch(String longer, String shorter)(Code)(Java Doc) void setRuleSet(RuleSet ruleSet)(Code)(Java Doc) public void setUseLocalNames(boolean useLocalNames)(Code)(Java Doc) public void setValue(Object value)(Code)(Java Doc) public void startDocument() throws org.xml.sax.SAXException(Code)(Java Doc) public void startElement(String uri, String localName, String qName, Attributes attributes) throws org.xml.sax.SAXException(Code)(Java Doc)
|
|
|