org.jacoco.report.internal.xml

## Class XMLElement

- java.lang.Object
- - org.jacoco.report.internal.xml.XMLElement

Direct Known Subclasses:
  HTMLElement, XMLDocument

    public class XMLElement
    extends Object

Simple API to create well formed XML streams. A `XMLElement` instance represents a single element in a XML document.

See Also:
  `XMLDocument`

### Field Summary

Fields
`protected Writer` `writer` Writer for content output

### Constructor Summary

Constructors
`protected` `XMLElement(Writer writer, String name)` Creates a new element for a XML document.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addChildElement(XMLElement child)` Adds the given child to this element.
`XMLElement` `attr(String name, int value)` Adds an attribute to this element.
`XMLElement` `attr(String name, long value)` Adds an attribute to this element.
`XMLElement` `attr(String name, String value)` Adds an attribute to this element.
`protected void` `beginOpenTag()` Emits the beginning of the open tag.
`void` `close()` Closes this element if it has not been closed before.
`XMLElement` `element(String name)` Creates a new child element for this element,
`XMLElement` `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

    protected XMLElement(Writer writer,
                         String name)

Creates a new element for a XML document.

Parameters:
  `writer` - all output will be written directly to this
  `name` - element name

### Method Detail

#### beginOpenTag

    protected void beginOpenTag()
                         throws IOException

Emits the beginning of the open tag. This method has to be called before other other methods are called on this element.

Throws:
  `IOException` - in case of problems with the writer

#### addChildElement

    protected void addChildElement(XMLElement child)
                            throws IOException

Adds the given child to this element. This will close all previous child elements.

Parameters:
  `child` - child element to add
Throws:
  `IOException` - in case of invalid nesting or problems with the writer

#### attr

    public XMLElement attr(String name,
                           String value)
                    throws IOException

Adds an attribute to this element. May only be called before an 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`
Returns:
  this element
Throws:
  `IOException` - in case of problems with the writer

#### attr

    public XMLElement attr(String name,
                           int value)
                    throws IOException

Adds an attribute to this element. May only be called before an 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
Returns:
  this element
Throws:
  `IOException` - in case of problems with the writer

#### attr

    public XMLElement attr(String name,
                           long value)
                    throws IOException

Adds an attribute to this element. May only be called before an 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
Returns:
  this element
Throws:
  `IOException` - in case of problems with the writer

#### text

    public XMLElement text(String text)
                    throws IOException

Adds the given text as a child to this node. The text will be quoted.

Parameters:
  `text` - text to add
Returns:
  this element
Throws:
  `IOException` - in case of problems with the writer

#### element

    public XMLElement element(String name)
                       throws IOException

Creates a new child element for this element,

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

#### close

    public void close()
               throws IOException

Closes this element if it has not been closed before.

Throws:
  `IOException` - in case of problems with the writer