|
||||||||||
| 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 String |
ATT_NAME
the "name" attribute. |
static String |
ATT_VERSION
the "version" attribute. |
static String |
DTD_ANY
the ANY placeholder. |
static String |
DTD_AT_LEAST_ONE
the at least one marker. |
static String |
DTD_ATTLIST
the AttList definition. |
static String |
DTD_CDATA
the CDATA placeholder. |
static String |
DTD_DOCTYPE
the DocType definition. |
static String |
DTD_ELEMENT
the Element definition. |
static String |
DTD_IMPLIED
the #IMPLIED placeholder. |
static String |
DTD_OPTIONAL
the optional marker. |
static String |
DTD_PCDATA
the #PCDATA placeholder. |
static String |
DTD_REQUIRED
the #REQUIRED placeholder. |
static String |
DTD_SEPARATOR
the option separator. |
static String |
DTD_ZERO_OR_MORE
the zero or more marker. |
static String |
PI
the parsing instructions "<?xml version=\"1.0\" encoding=\"utf-8\"?>" (may not show up in Javadoc due to tags!). |
static String |
VAL_NO
the value "no". |
static String |
VAL_YES
the value "yes". |
| Constructor Summary | |
|---|---|
XMLDocument()
initializes the factory with non-validating parser. |
|
XMLDocument(File file)
Creates a new instance of XMLDocument. |
|
XMLDocument(InputStream stream)
Creates a new instance of XMLDocument. |
|
XMLDocument(Reader reader)
Creates a new instance of XMLDocument. |
|
XMLDocument(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. |
Boolean |
evalBoolean(String xpath)
Evaluates and returns the boolean result of the XPath expression. |
Double |
evalDouble(String xpath)
Evaluates and returns the double result of the XPath expression. |
String |
evalString(String xpath)
Evaluates and returns the boolean result of the XPath expression. |
NodeList |
findNodes(String xpath)
Returns the nodes that the given xpath expression will find in the document. |
DocumentBuilder |
getBuilder()
returns the DocumentBuilder. |
static Vector<Element> |
getChildTags(Node parent)
returns all non tag-children from the given node. |
static Vector<Element> |
getChildTags(Node parent,
String name)
returns all non tag-children from the given node. |
static String |
getContent(Element node)
returns the text between the opening and closing tag of a node (performs a trim() on the result). |
String |
getDocType()
returns the current DOCTYPE, can be null. |
Document |
getDocument()
returns the parsed DOM document. |
DocumentBuilderFactory |
getFactory()
returns the DocumentBuilderFactory. |
Node |
getNode(String xpath)
Returns the node represented by the XPath expression. |
String |
getRevision()
Returns the revision string. |
String |
getRootNode()
returns the current root node. |
boolean |
getValidating()
returns whether a validating parser is used. |
static void |
main(String[] args)
for testing only. |
Document |
newDocument(String docType,
String rootNode)
creates a new Document with the given information. |
void |
print()
prints the current DOM document to standard out. |
Document |
read(File file)
parses the given file and returns a DOM document. |
Document |
read(InputStream stream)
parses the given stream and returns a DOM document. |
Document |
read(Reader reader)
parses the given reader and returns a DOM document. |
Document |
read(String xml)
parses the given XML string (can be XML or a filename) and returns a DOM Document. |
void |
setDocType(String docType)
sets the DOCTYPE-String to use in the XML output. |
void |
setDocument(Document newDocument)
sets the DOM document to use. |
void |
setRootNode(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! |
String |
toString()
returns the current DOM document as XML-string. |
void |
write(File file)
writes the current DOM document into the given file. |
void |
write(OutputStream stream)
writes the current DOM document into the given stream. |
void |
write(String file)
writes the current DOM document into the given file. |
void |
write(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 String PI
public static final String DTD_DOCTYPE
public static final String DTD_ELEMENT
public static final String DTD_ATTLIST
public static final String DTD_OPTIONAL
public static final String DTD_AT_LEAST_ONE
public static final String DTD_ZERO_OR_MORE
public static final String DTD_SEPARATOR
public static final String DTD_CDATA
public static final String DTD_ANY
public static final String DTD_PCDATA
public static final String DTD_IMPLIED
public static final String DTD_REQUIRED
public static final String ATT_VERSION
public static final String ATT_NAME
public static final String VAL_YES
public static final String VAL_NO
| Constructor Detail |
|---|
public XMLDocument()
throws Exception
Exception - if the construction fails
public XMLDocument(String xml)
throws Exception
xml - the xml to parse (if "Throws:
Exception - if the construction of the DocumentBuilder failssetValidating(boolean)
public XMLDocument(File file)
throws Exception
file - the XML file to parse
Exception - if the construction of the DocumentBuilder failssetValidating(boolean)
public XMLDocument(InputStream stream)
throws Exception
stream - the XML stream to parse
Exception - if the construction of the DocumentBuilder failssetValidating(boolean)
public XMLDocument(Reader reader)
throws Exception
reader - the XML reader to parse
Exception - if the construction of the DocumentBuilder failssetValidating(boolean)| Method Detail |
|---|
public DocumentBuilderFactory getFactory()
public DocumentBuilder getBuilder()
public boolean getValidating()
public void setValidating(boolean validating)
throws Exception
validating - whether to use a validating parser
Exception - if the instantiating of the DocumentBuilder failspublic Document getDocument()
public void setDocument(Document newDocument)
newDocument - the DOM document to usepublic void setDocType(String docType)
null the DOCTYPE is omitted.
docType - the DOCTYPE definition to use in XML outputpublic String getDocType()
null.
nullpublic void setRootNode(String rootNode)
rootNode - the root node to use in the XML outputpublic String getRootNode()
public void clear()
setRootNode(String),
setDocType(String)
public Document newDocument(String docType,
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 Document read(String xml)
throws Exception
xml - the xml to parse (if "Returns:Exception - if something goes wrong with the parsing
public Document read(File file)
throws Exception
file - the XML file to parse
Exception - if something goes wrong with the parsing
public Document read(InputStream stream)
throws Exception
stream - the XML stream to parse
Exception - if something goes wrong with the parsing
public Document read(Reader reader)
throws Exception
reader - the XML reader to parse
Exception - if something goes wrong with the parsing
public void write(String file)
throws Exception
file - the filename to write to
Exception - if something goes wrong with the parsing
public void write(File file)
throws Exception
file - the filename to write to
Exception - if something goes wrong with the parsing
public void write(OutputStream stream)
throws Exception
stream - the filename to write to
Exception - if something goes wrong with the parsing
public void write(Writer writer)
throws Exception
writer - the filename to write to
Exception - if something goes wrong with the parsingpublic static Vector<Element> getChildTags(Node parent)
parent - the node to get the children from
public static Vector<Element> getChildTags(Node parent,
String name)
parent - the node to get the children fromname - the name of the tags to return, "" for all
public NodeList findNodes(String xpath)
xpath - the XPath expression to run on the document
public Node getNode(String xpath)
xpath - the XPath expression to run on the document
public Boolean evalBoolean(String xpath)
xpath - the expression to evaluate
public Double evalDouble(String xpath)
xpath - the expression to evaluate
public String evalString(String xpath)
xpath - the expression to evaluate
public static String getContent(Element node)
trim() on the result).
node - the node to get the text from
public void print()
public String toString()
toString in class Objectpublic String getRevision()
getRevision in interface RevisionHandler
public static void main(String[] args)
throws Exception
args - the commandline arguments
Exception - if something goes wrong
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||