org.jacoco.report.internal.xml
Class XMLElement

java.lang.Object
  extended by org.jacoco.report.internal.xml.XMLElement
Direct Known Subclasses:
HTMLElement, ReportElement

public class XMLElement
extends Object

Simple API to create well formed XML streams with minimal memory overhead. An XMLElement instance represents a single element in an XML document. XMLElement can be used directly or might be subclassed for schema specific convenience methods.


Field Summary
protected  Writer writer
          Writer for content output
 
Constructor Summary
  XMLElement(String name, String pubId, String system, boolean standalone, String encoding, OutputStream output)
          Creates a root element of an XML document.
protected XMLElement(String name, XMLElement parent)
          Creates a new child element within an XML document.
 
Method Summary
 void attr(String name, int value)
          Adds an attribute to this element.
 void attr(String name, long value)
          Adds an attribute to this element.
 void attr(String name, String value)
          Adds an attribute to this element.
 void close()
          Closes this element if it has not been closed before.
 XMLElement element(String name)
          Creates a new child element for this element.
 void text(String text)
          Adds the given text as a child to this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected final Writer writer
Writer for content output

Constructor Detail

XMLElement

public XMLElement(String name,
                  String pubId,
                  String system,
                  boolean standalone,
                  String encoding,
                  OutputStream output)
           throws IOException
Creates a root element of an XML document.

Parameters:
name - element name
pubId - optional schema public identifier
system - optional schema system identifier
standalone - if true the document is declared as standalone
encoding - character encoding used for output
output - output stream will be closed if the root element is closed
Throws:
IOException - in case of problems with the underlying output

XMLElement

protected XMLElement(String name,
                     XMLElement parent)
              throws IOException
Creates a new child element within an XML document. May only be called before the parent element has been closed.

Parameters:
name - element name
parent - parent of this element
Throws:
IOException - in case of problems with the underlying output or if the parent element is already closed
Method Detail

attr

public final void attr(String name,
                       String value)
                throws IOException
Adds an attribute to this element. May only be called before a child element is added or this element has been closed. The attribute value will be quoted. If the value is null the attribute will not be added.

Parameters:
name - attribute name
value - attribute value or null
Throws:
IOException - in case of problems with the underlying output or if the element is already closed.

attr

public final void attr(String name,
                       int value)
                throws IOException
Adds an attribute to this element. May only be called before a child element is added or this element has been closed. The attribute value is the decimal representation of the given int value.

Parameters:
name - attribute name
value - attribute value
Throws:
IOException - in case of problems with the underlying output or if the element is already closed.

attr

public final void attr(String name,
                       long value)
                throws IOException
Adds an attribute to this element. May only be called before a child element is added or this element has been closed. The attribute value is the decimal representation of the given long value.

Parameters:
name - attribute name
value - attribute value
Throws:
IOException - in case of problems with the underlying output or if the element is already closed.

text

public final void text(String text)
                throws IOException
Adds the given text as a child to this node. The text will be quoted. May only be called before this element has been closed.

Parameters:
text - text to add
Throws:
IOException - in case of problems with the underlying output or if the element is already closed.

element

public XMLElement element(String name)
                   throws IOException
Creates a new child element for this element. Might be overridden in subclasses to return an instance of the subclass.

Parameters:
name - name of the child element
Returns:
child element instance
Throws:
IOException - in case of problems with the underlying output

close

public final void close()
                 throws IOException
Closes this element if it has not been closed before.

Throws:
IOException - in case of problems with the underlying output


Copyright © 2009–2025 Mountainminds GmbH & Co. KG. All rights reserved.