xml
Class XmlElementTextGen

java.lang.Object
  extended by xml.XmlElementTextGen

public class XmlElementTextGen
extends java.lang.Object

Supports the conversion of an XML DOM element to text.

This is really redundant now that JAXP supports DOM Load-and-Save (but note that DOM LS requires access to the Document containing the element).

An instance will supply the text string for a given XML DOM Element -- via its getText() method. Alternatively the text can be appended to a Writer -- via the writeText() method.

Construction time flag parameters determine whether or not the text has indentation, and whether or not it contains an XML declaration.

NB
Now (2007) JAXP element text generation output format seems to vary with the context -- e.g. a single line for an internally constructed DOM element, multiple lines with indentation for a DOM element read from an external source.


Constructor Summary
XmlElementTextGen(boolean doindent)
          Constructs a new XML text generator, that uses the given indentation setting, does not output an XML declaration, uses the standard encoding (UTF-8), and that uses the standard output buffer size.
XmlElementTextGen(boolean doindent, boolean doxmldecl)
          Constructs a new XML text generator, that uses the given indentation setting, generates an XML declaration or not, as specified, uses the standard encoding (UTF-8), and that uses the standard output buffer size.
XmlElementTextGen(boolean doindent, java.lang.String encoding, boolean doxmldecl)
          Constructs a new XML text generator, that uses the given indentation setting, generates an XML declaration or not, as specified, uses the given encoding, and that uses the standard output buffer size.
XmlElementTextGen(boolean doindent, java.lang.String encoding, boolean doxmldecl, int bufsize)
          Constructs a new XML text generator, that uses the given indentation setting, generates an XML declaration or not, as specified, and that uses the given encoding and output buffer size.
 
Method Summary
 java.lang.String getText(org.w3c.dom.Element el)
          Generates and returns the text for the given element.
 java.lang.String getText(org.w3c.dom.Element el, java.lang.String prfx, java.lang.String sffx)
          Generates the text for the given element, with the given prefix and suffix text attached, and returns the result.
static java.lang.String indentedLinesForPureXML(java.lang.String xml)
          Returns a multi-line indented version of the given pure XML text.
static java.lang.String linesForPureXML(java.lang.String xml)
          Returns a multi-line non-indented version of the given pure XML text.
 void writeText(org.w3c.dom.Element el, java.io.Writer wrtr)
          Generates the text for the given element, and writes it to the given writer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlElementTextGen

public XmlElementTextGen(boolean doindent)
                  throws javax.xml.transform.TransformerConfigurationException
Constructs a new XML text generator, that uses the given indentation setting, does not output an XML declaration, uses the standard encoding (UTF-8), and that uses the standard output buffer size.

Throws:
javax.xml.transform.TransformerConfigurationException

XmlElementTextGen

public XmlElementTextGen(boolean doindent,
                         boolean doxmldecl)
                  throws javax.xml.transform.TransformerConfigurationException
Constructs a new XML text generator, that uses the given indentation setting, generates an XML declaration or not, as specified, uses the standard encoding (UTF-8), and that uses the standard output buffer size.

Throws:
javax.xml.transform.TransformerConfigurationException

XmlElementTextGen

public XmlElementTextGen(boolean doindent,
                         java.lang.String encoding,
                         boolean doxmldecl)
                  throws javax.xml.transform.TransformerConfigurationException
Constructs a new XML text generator, that uses the given indentation setting, generates an XML declaration or not, as specified, uses the given encoding, and that uses the standard output buffer size.

Throws:
javax.xml.transform.TransformerConfigurationException

XmlElementTextGen

public XmlElementTextGen(boolean doindent,
                         java.lang.String encoding,
                         boolean doxmldecl,
                         int bufsize)
                  throws javax.xml.transform.TransformerConfigurationException
Constructs a new XML text generator, that uses the given indentation setting, generates an XML declaration or not, as specified, and that uses the given encoding and output buffer size.

Throws:
javax.xml.transform.TransformerConfigurationException
Method Detail

getText

public java.lang.String getText(org.w3c.dom.Element el)
                         throws javax.xml.transform.TransformerException
Generates and returns the text for the given element. Note that in some contexts this text is indented, regardless of the construction-time indentation setting.

Throws:
javax.xml.transform.TransformerException

getText

public java.lang.String getText(org.w3c.dom.Element el,
                                java.lang.String prfx,
                                java.lang.String sffx)
                         throws javax.xml.transform.TransformerException
Generates the text for the given element, with the given prefix and suffix text attached, and returns the result. Note that in some contexts the element text is indented, regardless of the construction-time indentation setting.

Throws:
javax.xml.transform.TransformerException

writeText

public void writeText(org.w3c.dom.Element el,
                      java.io.Writer wrtr)
               throws javax.xml.transform.TransformerException
Generates the text for the given element, and writes it to the given writer. Note that the element text is indented, regardless of the construction-time indentation setting.

Throws:
javax.xml.transform.TransformerException

indentedLinesForPureXML

public static java.lang.String indentedLinesForPureXML(java.lang.String xml)
Returns a multi-line indented version of the given pure XML text.


linesForPureXML

public static java.lang.String linesForPureXML(java.lang.String xml)
Returns a multi-line non-indented version of the given pure XML text.