|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectweka.core.xml.XMLDocument
public class XMLDocument
This class offers some methods for generating, reading and writing
XML documents.
It can only handle UTF-8.
PI| Field Summary | |
|---|---|
static java.lang.String |
PI
the parsing instructions "<?xml version=\"1.0\" encoding=\"utf-8\"?>" (may not show up in Javadoc due to tags!) |
| Constructor Summary | |
|---|---|
XMLDocument()
initializes the factory with non-validating parser |
|
XMLDocument(java.io.File file)
Creates a new instance of XMLDocument |
|
XMLDocument(java.io.InputStream stream)
Creates a new instance of XMLDocument |
|
XMLDocument(java.io.Reader reader)
Creates a new instance of XMLDocument |
|
XMLDocument(java.lang.String xml)
Creates a new instance of XMLDocument |
|
| Method Summary | |
|---|---|
void |
clear()
sets up an empty DOM document, with the current DOCTYPE and root node |
javax.xml.parsers.DocumentBuilder |
getBuilder()
returns the DocumentBuilder |
static java.util.Vector |
getChildTags(org.w3c.dom.Node parent)
returns all non tag-children from the given node |
static java.lang.String |
getContent(org.w3c.dom.Element node)
returns the text between the opening and closing tag of a node (performs a trim() on the result) |
java.lang.String |
getDocType()
returns the current DOCTYPE, can be null |
org.w3c.dom.Document |
getDocument()
returns the parsed DOM document |
javax.xml.parsers.DocumentBuilderFactory |
getFactory()
returns the DocumentBuilderFactory |
java.lang.String |
getRootNode()
returns the current root node |
boolean |
getValidating()
returns whether a validating parser is used |
static void |
main(java.lang.String[] args)
for testing only. |
org.w3c.dom.Document |
newDocument(java.lang.String docType,
java.lang.String rootNode)
creates a new Document with the given information |
void |
print()
prints the current DOM document to standard out |
org.w3c.dom.Document |
read(java.io.File file)
parses the given file and returns a DOM document |
org.w3c.dom.Document |
read(java.io.InputStream stream)
parses the given stream and returns a DOM document |
org.w3c.dom.Document |
read(java.io.Reader reader)
parses the given reader and returns a DOM document |
org.w3c.dom.Document |
read(java.lang.String xml)
parses the given XML string (can be XML or a filename) and returns a DOM Document |
void |
setDocType(java.lang.String docType)
sets the DOCTYPE-String to use in the XML output. |
void |
setDocument(org.w3c.dom.Document newDocument)
sets the DOM document to use |
void |
setRootNode(java.lang.String rootNode)
sets the root node to use in the XML output. |
void |
setValidating(boolean validating)
sets whether to use a validating parser or not. Note: this does clear the current DOM document! |
java.lang.String |
toString()
returns the current DOM document as XML-string |
void |
write(java.io.File file)
writes the current DOM document into the given file |
void |
write(java.io.OutputStream stream)
writes the current DOM document into the given stream |
void |
write(java.lang.String file)
writes the current DOM document into the given file |
void |
write(java.io.Writer writer)
writes the current DOM document into the given writer |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String PI
| Constructor Detail |
|---|
public XMLDocument()
throws java.lang.Exception
java.lang.Exception
public XMLDocument(java.lang.String xml)
throws java.lang.Exception
xml - the xml to parse (if "Throws:
java.lang.Exception - if the construction of the DocumentBuilder failssetValidating(boolean)
public XMLDocument(java.io.File file)
throws java.lang.Exception
file - the XML file to parse
java.lang.Exception - if the construction of the DocumentBuilder failssetValidating(boolean)
public XMLDocument(java.io.InputStream stream)
throws java.lang.Exception
stream - the XML stream to parse
java.lang.Exception - if the construction of the DocumentBuilder failssetValidating(boolean)
public XMLDocument(java.io.Reader reader)
throws java.lang.Exception
reader - the XML reader to parse
java.lang.Exception - if the construction of the DocumentBuilder failssetValidating(boolean)| Method Detail |
|---|
public javax.xml.parsers.DocumentBuilderFactory getFactory()
public javax.xml.parsers.DocumentBuilder getBuilder()
public boolean getValidating()
public void setValidating(boolean validating)
throws java.lang.Exception
validating - whether to use a validating parser
java.lang.Exception - if the instantiating of the DocumentBuilder failspublic org.w3c.dom.Document getDocument()
public void setDocument(org.w3c.dom.Document newDocument)
newDocument - the DOM document to usepublic void setDocType(java.lang.String docType)
null the DOCTYPE is omitted.
docType - the DOCTYPE definition to use in XML outputpublic java.lang.String getDocType()
null
nullpublic void setRootNode(java.lang.String rootNode)
docType - the DOCTYPE definition to use in XML outputpublic java.lang.String getRootNode()
public void clear()
setRootNode(String),
setDocType(String)
public org.w3c.dom.Document newDocument(java.lang.String docType,
java.lang.String rootNode)
docType - the DOCTYPE definition (no checking happens!), can be nullrootNode - the name of the root node (must correspond to the one
given in docType)
public org.w3c.dom.Document read(java.lang.String xml)
throws java.lang.Exception
xml - the xml to parse (if "Returns:if - something goes wrong with the parsing
java.lang.Exception
public org.w3c.dom.Document read(java.io.File file)
throws java.lang.Exception
file - the XML file to parse
if - something goes wrong with the parsing
java.lang.Exception
public org.w3c.dom.Document read(java.io.InputStream stream)
throws java.lang.Exception
stream - the XML stream to parse
if - something goes wrong with the parsing
java.lang.Exception
public org.w3c.dom.Document read(java.io.Reader reader)
throws java.lang.Exception
reader - the XML reader to parse
if - something goes wrong with the parsing
java.lang.Exception
public void write(java.lang.String file)
throws java.lang.Exception
file - the filename to write to
if - something goes wrong with the parsing
java.lang.Exception
public void write(java.io.File file)
throws java.lang.Exception
file - the filename to write to
if - something goes wrong with the parsing
java.lang.Exception
public void write(java.io.OutputStream stream)
throws java.lang.Exception
file - the filename to write to
if - something goes wrong with the parsing
java.lang.Exception
public void write(java.io.Writer writer)
throws java.lang.Exception
file - the filename to write to
if - something goes wrong with the parsing
java.lang.Exceptionpublic static java.util.Vector getChildTags(org.w3c.dom.Node parent)
parent - the node to get the children from
public static java.lang.String getContent(org.w3c.dom.Element node)
trim() on the result)
node - the node to get the text from
public void print()
public java.lang.String toString()
toString in class java.lang.Objectdocument - the document to return as XML-string
java.lang.Exception - if anything goes wrong initializing the parsing
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||