|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.enough.polish.xml.XmlDomParser
public class XmlDomParser
Parses XML documents in a single step.
This is more comfortable than using the XmlPullParser but uses somewhat more memory since the complete document is held memory.
Following example code demonstrates the usage:
String document = "<rootelement><childnode x=\"10\">textvalue10</childnode><childnode x=\"20\">textvalue20</childnode></rootelement>";
XmlDomNode root = XmlDomParser.parseTree(document);
System.out.println("root " + root.getName() + ", has " + root.getChildCount() + " children");
// indirect access:
for (int i=0; i < root.getChildCount(); i++ ) {
XmlDomNode child = root.getChild(i);
System.out.println("child: " + child.getName() );
System.out.println("child: " + child.getName() + ", x=" + child.getAttribute("x") + ", text=" + child.getText() );
}
// direct access:
XmlDomNode child = root.getChild("childnode");
System.out.println("first child: " + child.getName() + ", x=" + child.getAttribute("x") + ", text=" + child.getText() );
Copyright Enough Software 2006 - 2009
history
Apr 8, 2006 - mkoch creation
| Constructor Summary | |
|---|---|
XmlDomParser()
|
|
| Method Summary | |
|---|---|
static XmlDomNode |
parseTree(InputStream in)
Parses an XML document and returns it's root element as an XmlDomNode. |
static XmlDomNode |
parseTree(InputStream in,
String encoding)
Parses an XML document and returns it's root element as an XmlDomNode. |
static XmlDomNode |
parseTree(String document)
Parses an XML document and returns it's root element as an XmlDomNode. |
static XmlDomNode |
parseTree(String document,
String encoding)
Parses an XML document and returns it's root element as an XmlDomNode. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XmlDomParser()
| Method Detail |
|---|
public static XmlDomNode parseTree(String document)
document - the document.
RuntimeException - when the parsing fails
public static XmlDomNode parseTree(String document,
String encoding)
throws UnsupportedEncodingException
document - the document.encoding - the encoding, e.g. "UTF-8"
UnsupportedEncodingException
RuntimeException - when the parsing failspublic static XmlDomNode parseTree(InputStream in)
in - input stream of the document.
RuntimeException - when the parsing fails
public static XmlDomNode parseTree(InputStream in,
String encoding)
throws UnsupportedEncodingException
in - input stream of the document.encoding - the encoding, e.g. "UTF-8"
UnsupportedEncodingException
RuntimeException - when the parsing fails
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||