public class DOMElementWriter extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DOMElementWriter.XmlNamespacePolicy
Whether namespaces should be ignored for elements and attributes.
|
Modifier and Type | Field and Description |
---|---|
protected String[] |
knownEntities
Don't try to be too smart but at least recognize the predefined
entities.
|
Constructor and Description |
---|
DOMElementWriter()
Create an element writer.
|
DOMElementWriter(boolean xmlDeclaration)
Create an element writer
XML namespaces will be ignored.
|
DOMElementWriter(boolean xmlDeclaration,
DOMElementWriter.XmlNamespacePolicy namespacePolicy)
Create an element writer
XML namespaces will be ignored.
|
Modifier and Type | Method and Description |
---|---|
void |
closeElement(Element element,
Writer out,
int indent,
String indentWith,
boolean hasChildren)
Writes a DOM tree to a stream.
|
String |
encode(String value)
Escape <, > & ', " as their entities and
drop characters that are illegal in XML documents.
|
String |
encodedata(String value)
Drop characters that are illegal in XML documents.
|
String |
encodetext(String value)
Escape <, > & as their entities and
drop characters that are illegal in XML documents.
|
boolean |
isLegalCharacter(char c)
Is the given character allowed inside an XML document?
|
boolean |
isReference(String ent)
Is the given argument a character or entity reference?
|
void |
openElement(Element element,
Writer out,
int indent,
String indentWith)
Writes the opening tag - including all attributes -
corresponding to a DOM element.
|
void |
openElement(Element element,
Writer out,
int indent,
String indentWith,
boolean hasChildren)
Writes the opening tag - including all attributes -
corresponding to a DOM element.
|
void |
write(Element root,
OutputStream out)
Writes a DOM tree to a stream in UTF8 encoding.
|
void |
write(Element element,
Writer out,
int indent,
String indentWith)
Writes a DOM tree to a stream.
|
void |
writeXMLDeclaration(Writer wri)
Writes the XML declaration if xmlDeclaration is true.
|
protected String[] knownEntities
public DOMElementWriter()
public DOMElementWriter(boolean xmlDeclaration)
xmlDeclaration
- flag to indicate whether the ?xml? declaration
should be included.public DOMElementWriter(boolean xmlDeclaration, DOMElementWriter.XmlNamespacePolicy namespacePolicy)
xmlDeclaration
- flag to indicate whether the ?xml? declaration
should be included.namespacePolicy
- the policy to use.public void write(Element root, OutputStream out) throws IOException
root
- the root element of the DOM tree.out
- the outputstream to write to.IOException
- if an error happens while writing to the stream.public void writeXMLDeclaration(Writer wri) throws IOException
wri
- the writer to write to.IOException
- if there is an error.public void write(Element element, Writer out, int indent, String indentWith) throws IOException
element
- the Root DOM element of the treeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.IOException
- if an error happens while writing to the stream.public void openElement(Element element, Writer out, int indent, String indentWith) throws IOException
element
- the DOM element to writeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.IOException
- if an error happens while writing to the stream.public void openElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren) throws IOException
element
- the DOM element to writeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.hasChildren
- whether this element has children.IOException
- if an error happens while writing to the stream.public void closeElement(Element element, Writer out, int indent, String indentWith, boolean hasChildren) throws IOException
element
- the Root DOM element of the treeout
- where to send the outputindent
- number ofindentWith
- string that should be used to indent the
corresponding tag.hasChildren
- if true indent.IOException
- if an error happens while writing to the stream.public String encode(String value)
value
- the string to encode.public String encodetext(String value)
value
- the string to encode.public String encodedata(String value)
Also ensure that we are not including an ]]>
marker by replacing that sequence with
]]>
.
See XML 1.0 2.2 http://www.w3.org/TR/1998/REC-xml-19980210#charsets and 2.7 http://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect.
value
- the value to be encoded.public boolean isReference(String ent)
ent
- the value to be checked.public boolean isLegalCharacter(char c)
See XML 1.0 2.2 http://www.w3.org/TR/1998/REC-xml-19980210#charsets.
c
- the character to test.Copyright © 2008–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.