|
TopoWeb Commons API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.topoweb.xml.XmlUtil
Utility for manipulating XML structures. Provides convenience methods for writing and reading DOM structures to and from streams.
Field Summary |
Fields inherited from interface org.topoweb.xml.XmlUtilConstants |
XML_DECLARATION, XML_DECLARATION_VERSION1_UTF8 |
Method Summary | |
static java.lang.String |
getText(org.w3c.dom.Element element)
Returns the text of the given element . |
static org.w3c.dom.Document |
newDocument()
Returns a newly created DOM document node. |
static org.w3c.dom.Document |
readDocument(java.io.InputStream is)
Returns a DOM document node created and read from the given input stream |
static org.w3c.dom.Document |
readDocument(java.io.InputStream is,
javax.xml.parsers.DocumentBuilder builder)
Returns a DOM document node created and read from the given input stream |
static org.w3c.dom.Document |
readDocument(java.io.Reader reader)
Returns a DOM document node created and read from the given reader. |
static org.w3c.dom.Document |
readDocument(java.io.Reader reader,
javax.xml.parsers.DocumentBuilder builder)
Returns a DOM document node created and read from the given reader. |
static org.w3c.dom.Document |
readDocument(javax.xml.transform.Source src)
Returns a DOM document node created and read from the given source. |
static org.w3c.dom.Document |
readDocument(javax.xml.transform.Source src,
javax.xml.parsers.DocumentBuilder builder)
Returns a DOM document node created using the given builder
and read from the given source. |
static org.w3c.dom.Document |
readDocument(java.lang.String xml,
javax.xml.parsers.DocumentBuilder builder)
Returns a DOM document node created and read from the given xml string. |
static void |
setText(org.w3c.dom.Element element,
org.w3c.dom.Document doc,
java.lang.String txt)
Sets text for the given element in the
specified DOM document. |
static java.lang.String |
toXmlString(org.w3c.dom.Node node)
Returns a well-formed string representation of the given DOM node
. |
static void |
transform(javax.xml.transform.Source src,
javax.xml.transform.Result dtn)
Transforms the given source to the specified destination. |
static void |
writeDocument(java.io.OutputStream out,
org.w3c.dom.Document doc)
Writes the given document to the specified output stream. |
static void |
writeDocument(java.io.OutputStream out,
org.w3c.dom.Document doc,
java.lang.String dtd)
Writes the given document to the specified output stream using the specified inlined DTD declaration. |
static void |
writeDocument(java.io.Writer writer,
org.w3c.dom.Document doc)
Writes the given document to the specified writer. |
static void |
writeDocument(java.io.Writer writer,
org.w3c.dom.Document doc,
java.lang.String dtd)
Writes the given document to the specified writer using the specified inlined DTD declaration. |
static void |
writeNode(java.io.OutputStream out,
org.w3c.dom.Node node)
Writes the given DOM node to the specified output stream. |
static void |
writeNode(java.io.Writer writer,
org.w3c.dom.Node node)
Writes the given DOM node to the specified writer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static java.lang.String toXmlString(org.w3c.dom.Node node) throws javax.xml.transform.TransformerException
node
.
node
- the DOM node
node
javax.xml.transform.TransformerException
- if a transform error occurswriteNode(Writer,Node)
public static void writeDocument(java.io.OutputStream out, org.w3c.dom.Document doc) throws java.io.IOException, javax.xml.transform.TransformerException
writeDocument(out, doc, null)
.
out
- the output stream written todoc
- the DOM document
java.io.IOException
- if there is an error while writing to out
javax.xml.transform.TransformerException
- if a transform error occurswriteDocument(OutputStream,Document,String)
,
writeDocument(Writer,Document)
public static void writeDocument(java.io.OutputStream out, org.w3c.dom.Document doc, java.lang.String dtd) throws java.io.IOException, javax.xml.transform.TransformerException
dtd
, may be
null
. This method invokes the writeDocument(Writer,Document,String)
method.
Warning: No checks are performed on the dtd
string. Consequently, the XML written to the stream will
not be well-formed if dtd
is not.
out
- the output stream written todoc
- the DOM documentdtd
- the inlined DTD for doc
java.io.IOException
- if there is an error while writing to out
javax.xml.transform.TransformerException
- if a transform error occurswriteDocument(Writer,Document,String)
public static void writeDocument(java.io.Writer writer, org.w3c.dom.Document doc) throws java.io.IOException, javax.xml.transform.TransformerException
writeDocument(out, doc, null)
.
writer
- the Writer
written todoc
- the DOM document
java.io.IOException
- if there is an error while writing to out
javax.xml.transform.TransformerException
- if a transform error occurswriteDocument(Writer,Document,String)
,
writeDocument(OutputStream,Document)
public static void writeDocument(java.io.Writer writer, org.w3c.dom.Document doc, java.lang.String dtd) throws java.io.IOException, javax.xml.transform.TransformerException
dtd
argument
may be null
. The method first writes a line containing
the XML declaration.
If dtd
is not null
, then it too is written.
Finally, the writeNode(Writer,Node)
method is invoked.
Warning: No checks are performed on the dtd
string. Consequently, the XML written to the stream will
not be well-formed if dtd
is not.
writer
- the Writer
written todoc
- the DOM documentdtd
- the inlined DTD for doc
java.io.IOException
- if there is an error while writing to out
javax.xml.transform.TransformerException
- if a transform error occurswriteDocument(OutputStream,Document,String)
,
XmlUtilConstants.XML_DECLARATION
,
writeNode(Writer,Node)
public static void writeNode(java.io.Writer writer, org.w3c.dom.Node node) throws javax.xml.transform.TransformerException
node
is written as a well-formed XML snippet (i.e. w/o header declarations).
This method is equivalent to invoking transform(new DOMSource(node), new StreamResult(writer))
.
writer
- the Writer
written tonode
- the DOM node
javax.xml.transform.TransformerException
- if a transform error occurstransform(Source,Result)
public static void writeNode(java.io.OutputStream out, org.w3c.dom.Node node) throws javax.xml.transform.TransformerException
node
is written as a well-formed XML snippet (i.e. w/o header declarations).
This method is equivalent to invoking transform(new DOMSource(node), new StreamResult(out))
.
out
- the output stream written tonode
- the DOM node
javax.xml.transform.TransformerException
- if a transform error occurstransform(Source,Result)
public static void transform(javax.xml.transform.Source src, javax.xml.transform.Result dtn) throws javax.xml.transform.TransformerException
javax.xml.transform.Transformer
with
the following output properites:
- method : xml
- indent : yes
- omit-xml-declaration : yes
src
- the source (Source
)dtn
- the destination (Result
)
javax.xml.transform.TransformerException
- if a transform error occurspublic static org.w3c.dom.Document newDocument() throws javax.xml.parsers.ParserConfigurationException
Document
from a newly created DocumentBuilder
. This method is useful for building a DOM tree from scratch.
Document
javax.xml.parsers.ParserConfigurationException
- If the document builder cannot be properly initializedreadDocument(Source)
public static org.w3c.dom.Document readDocument(javax.xml.transform.Source src) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerException
src
- the source from which the returned document is
constructed
src
javax.xml.parsers.ParserConfigurationException
- If the document builder cannot be properly initialized
javax.xml.transform.TransformerException
- if a transform error occursnewDocument()
public static org.w3c.dom.Document readDocument(javax.xml.transform.Source src, javax.xml.parsers.DocumentBuilder builder) throws javax.xml.transform.TransformerException
builder
and read from the given source.
src
- the source from which the returned document is
constructedbuilder
- the factory used to create the returned document
instance
src
javax.xml.transform.TransformerException
- if a transform error occursnewDocument()
public static org.w3c.dom.Document readDocument(java.io.InputStream is) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerException
is
- the input stream from which the returned document is
constructed
is
javax.xml.parsers.ParserConfigurationException
- If the document builder cannot be properly initialized
javax.xml.transform.TransformerException
- if a transform error occurspublic static org.w3c.dom.Document readDocument(java.io.InputStream is, javax.xml.parsers.DocumentBuilder builder) throws javax.xml.transform.TransformerException
is
- the input stream from which the returned document is
constructedbuilder
- the factory used to create the returned document
instance
is
javax.xml.transform.TransformerException
- if a transform error occurspublic static org.w3c.dom.Document readDocument(java.io.Reader reader) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerException
reader
- the Reader
from which the returned
document is constructed
reader
javax.xml.parsers.ParserConfigurationException
- If the document builder cannot be properly initialized
javax.xml.transform.TransformerException
- if a transform error occurspublic static org.w3c.dom.Document readDocument(java.io.Reader reader, javax.xml.parsers.DocumentBuilder builder) throws javax.xml.transform.TransformerException
reader
- the Reader
from which the returned
document is constructed
reader
javax.xml.parsers.ParserConfigurationException
- If the document builder cannot be properly initialized
javax.xml.transform.TransformerException
- if a transform error occurspublic static org.w3c.dom.Document readDocument(java.lang.String xml, javax.xml.parsers.DocumentBuilder builder) throws javax.xml.transform.TransformerException
xml
string.
xml
- the XML snippet from which the returned
document is constructed
reader
javax.xml.parsers.ParserConfigurationException
- If the document builder cannot be properly initialized
javax.xml.transform.TransformerException
- if a transform error occurspublic static java.lang.String getText(org.w3c.dom.Element element)
element
. The element is
not expected to contain sub-elements. The behaviour of this method
is undefined for elements that themselves contain sub-elements.
element
- the DOM element
public static void setText(org.w3c.dom.Element element, org.w3c.dom.Document doc, java.lang.String txt)
element
in the
specified DOM document. The behviour is undefined if element
does not belong to doc
.
element
- the element whose text is to be setdoc
- the document to which element
belongstxt
- the text
|
TopoWeb Commons API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |