Class DocumentFragment

java.lang.Object
fi.iki.jmtilli.javaxmlfrag.DocumentFragment

public class DocumentFragment
extends java.lang.Object
Fragment of an XML document. Document fragments can either be text fragments (have textual content, can't have children or attributes) or tags (can have both children or attributes but don't contain text themselves -- but can contain text fragment children). There are different families of getters and setters:
  • getAttr* and setAttr* get and set the attribute values
  • getThis* and setThis* get and set the textual contents of this element
  • get* and set* get and set the textual contents of a named subelement
  • get*Object and set*Object use null to represent missing data
  • get*NotNull throw a XMLValueMissingException if data is missing
Note that the getThis* family and the get* family of methods are slightly different: the getThis* family handles empty string as null, while the get* family handles a missing element as null and an empty string as an empty string. Two methods, getThisStringObjectEmptyIsNull and getThisStringObjectEmptyIsEmpty are provided for strings but for data types other than strings, the getThis* family handles empty string as null.
  • Constructor Summary

    Constructors 
    Constructor Description
    DocumentFragment​(java.lang.String tag)
    Construct an element with no children and no attributes.
    DocumentFragment​(java.lang.String tag, java.util.List<DocumentFragment> children)
    Construct an element with no attributes
    DocumentFragment​(java.lang.String tag, java.util.List<DocumentFragment> children, java.util.Map<java.lang.String,​java.lang.String> attributes)
    Construct an element
    DocumentFragment​(java.lang.String tag, java.util.Map<java.lang.String,​java.lang.String> attributes)
    Construct an element with no children
  • Method Summary

    Modifier and Type Method Description
    void add​(DocumentFragment child)
    Convenience method for adding a child.
    DocumentFragment add​(java.lang.String tag)
    Convenience method for adding a child by tag name.
    void addChild​(DocumentFragment child)
    Deprecated.
    Use add(child)
    void addTextChild​(java.lang.String text)
    Convenience method for adding a text child.
    void assertTag​(java.lang.String tag)
    Assert that the tag name is the specified.
    org.w3c.dom.Node convertToDomNode​(org.w3c.dom.Document doc)
    Convert the XML to a DOM node.
    DocumentFragment get​(java.lang.String tag)
    Get the only child with the specified tag.
    byte getAttrByte​(java.lang.String attr, byte default_value)
    Get a byte attribute
    byte getAttrByteNotNull​(java.lang.String attr)
    Get a byte attribute that must be non-null.
    java.lang.Byte getAttrByteObject​(java.lang.String attr)
    Get a byte attribute or null
    double getAttrDouble​(java.lang.String attr, double default_value)
    Get a double attribute
    double getAttrDoubleNotNull​(java.lang.String attr)
    Get a double attribute that must be non-null.
    java.lang.Double getAttrDoubleObject​(java.lang.String attr)
    Get a double attribute or null
    float getAttrFloat​(java.lang.String attr, float default_value)
    Get a float attribute
    float getAttrFloatNotNull​(java.lang.String attr)
    Get a float attribute that must be non-null.
    java.lang.Float getAttrFloatObject​(java.lang.String attr)
    Get a float attribute or null
    java.util.Map<java.lang.String,​java.lang.String> getAttributes()
    Get the attributes of the element.
    int getAttrInt​(java.lang.String attr, int default_value)
    Get an integer attribute
    int getAttrIntNotNull​(java.lang.String attr)
    Get an integer attribute that must be non-null.
    java.lang.Integer getAttrIntObject​(java.lang.String attr)
    Get an integer attribute or null
    long getAttrLong​(java.lang.String attr, long default_value)
    Get a long attribute
    long getAttrLongNotNull​(java.lang.String attr)
    Get a long attribute that must be non-null.
    java.lang.Long getAttrLongObject​(java.lang.String attr)
    Get a long attribute or null
    short getAttrShort​(java.lang.String attr, short default_value)
    Get a short attribute
    short getAttrShortNotNull​(java.lang.String attr)
    Get a short attribute that must be non-null.
    java.lang.Short getAttrShortObject​(java.lang.String attr)
    Get a short attribute or null
    java.lang.String getAttrString​(java.lang.String attr, java.lang.String default_value)
    Get a string attribute
    java.lang.String getAttrStringNotNull​(java.lang.String attr)
    Get a string attribute that must be non-null.
    java.lang.String getAttrStringObject​(java.lang.String attr)
    Get a string attribute or null
    byte getByte​(java.lang.String element, byte default_value)
    Get a byte text in enclosing element.
    byte getByteNotNull​(java.lang.String element)
    Get a byte text that must be non-null in enclosing element.
    java.lang.Byte getByteObject​(java.lang.String element)
    Get a byte text in enclosing element or null.
    java.util.List<DocumentFragment> getChildren()
    Get the children of the element.
    double getDouble​(java.lang.String element, double default_value)
    Get a double text in enclosing element.
    double getDoubleNotNull​(java.lang.String element)
    Get a double text that must be non-null in enclosing element.
    java.lang.Double getDoubleObject​(java.lang.String element)
    Get a double text in enclosing element or null.
    float getFloat​(java.lang.String element, float default_value)
    Get a float text in enclosing element.
    float getFloatNotNull​(java.lang.String element)
    Get a float text that must be non-null in enclosing element.
    java.lang.Float getFloatObject​(java.lang.String element)
    Get a float text in enclosing element or null.
    int getInt​(java.lang.String element, int default_value)
    Get an integer text in enclosing element.
    int getIntNotNull​(java.lang.String element)
    Get an integer text that must be non-null in enclosing element.
    java.lang.Integer getIntObject​(java.lang.String element)
    Get an integer text in enclosing element or null.
    long getLong​(java.lang.String element, long default_value)
    Get a long text in enclosing element.
    long getLongNotNull​(java.lang.String element)
    Get a long text that must be non-null in enclosing element.
    java.lang.Long getLongObject​(java.lang.String element)
    Get a long text in enclosing element or null.
    java.util.ArrayList<DocumentFragment> getMulti​(java.lang.String tag)
    Get a list of children with the specified tag
    java.util.List<DocumentFragment> getNonTextChildren()
    Get the non-text children of the element.
    DocumentFragment getNotNull​(java.lang.String tag)
    Get the only child with the specified tag, asserting it is non-null.
    DocumentFragment getOrCreate​(java.lang.String element)
    Return the element with the tag name, creating it if nonexistent.
    short getShort​(java.lang.String element, short default_value)
    Get a short text in enclosing element.
    short getShortNotNull​(java.lang.String element)
    Get a short text that must be non-null in enclosing element.
    java.lang.Short getShortObject​(java.lang.String element)
    Get a short text in enclosing element or null.
    java.lang.String getString​(java.lang.String element, java.lang.String default_value)
    Get text in enclosing element.
    java.lang.String getStringNotNull​(java.lang.String element)
    Get text that must be non-null in enclosing element.
    java.lang.String getStringObject​(java.lang.String element)
    Get text in enclosing element or null.
    java.lang.String getTag()
    Get the tag name of the element.
    java.lang.String getText()
    Return the text of the element.
    byte getThisByte​(byte default_value)
    Get a byte text in this element.
    byte getThisByteNotNull()
    Get a byte text that must be non-null in this element.
    java.lang.Byte getThisByteObject()
    Get a byte text in this element or null.
    double getThisDouble​(double default_value)
    Get a double text in this element.
    double getThisDoubleNotNull()
    Get a double text that must be non-null in this element.
    java.lang.Double getThisDoubleObject()
    Get a double text in this element or null.
    float getThisFloat​(float default_value)
    Get a float text in this element.
    float getThisFloatNotNull()
    Get a float text that must be non-null in this element.
    java.lang.Float getThisFloatObject()
    Get a float text in this element or null.
    int getThisInt​(int default_value)
    Get an integer text in this element.
    int getThisIntNotNull()
    Get an integer text that must be non-null in this element.
    java.lang.Integer getThisIntObject()
    Get an integer text in this element or null.
    long getThisLong​(long default_value)
    Get a long text in this element.
    long getThisLongNotNull()
    Get a long text that must be non-null in this element.
    java.lang.Long getThisLongObject()
    Get a long text in this element or null.
    short getThisShort​(short default_value)
    Get a short text in this element.
    short getThisShortNotNull()
    Get a short text that must be non-null in this element.
    java.lang.Short getThisShortObject()
    Get a short text in this element or null.
    java.lang.String getThisString​(java.lang.String default_value)
    Get text in this element.
    java.lang.String getThisStringNotEmpty()
    Get text in this element that must be non-empty.
    java.lang.String getThisStringObjectEmptyIsEmpty()
    Get text in this element.
    java.lang.String getThisStringObjectEmptyIsNull()
    Get text in this element or null.
    boolean isTextElement()
    Test whether this element is a text element.
    static DocumentFragment newText​(java.lang.String text)
    Construct a text element.
    DocumentFragment remove​(java.lang.String tag)
    Remove and get the only child with the specified tag.
    java.util.List<DocumentFragment> removeAll()
    Remove and get a list of all children
    void removeAttr​(java.lang.String attr)
    Convenience method for removing an attribute.
    java.util.ArrayList<DocumentFragment> removeMulti​(java.lang.String tag)
    Remove and get a list of children with the specified tag
    DocumentFragment set​(java.lang.String element)
    Return the element with the tag name, creating it if nonexistent and clear its contents if existent.
    void setAttr​(java.lang.String attr, java.lang.String val)
    Deprecated.
    use setAttrString
    void setAttrByte​(java.lang.String attr, byte val)
    Set a byte attribute.
    void setAttrByteObject​(java.lang.String attr, java.lang.Byte val)
    Set a byte attribute or remove the attribute.
    void setAttrDouble​(java.lang.String attr, double val)
    Set a double attribute.
    void setAttrDoubleObject​(java.lang.String attr, java.lang.Double val)
    Set a double attribute or remove the attribute.
    void setAttrFloat​(java.lang.String attr, float val)
    Set a float attribute.
    void setAttrFloatObject​(java.lang.String attr, java.lang.Float val)
    Set a float attribute or remove the attribute.
    void setAttrInt​(java.lang.String attr, int val)
    Set an int attribute.
    void setAttrIntObject​(java.lang.String attr, java.lang.Integer val)
    Set a int attribute or remove the attribute.
    void setAttrLong​(java.lang.String attr, long val)
    Set a long attribute.
    void setAttrLongObject​(java.lang.String attr, java.lang.Long val)
    Set a long attribute or remove the attribute.
    void setAttrShort​(java.lang.String attr, short val)
    Set a short attribute.
    void setAttrShortObject​(java.lang.String attr, java.lang.Short val)
    Set a short attribute or remove the attribute.
    void setAttrString​(java.lang.String attr, java.lang.String val)
    Convenience method for setting an attribute.
    void setAttrStringObject​(java.lang.String attr, java.lang.String val)
    Set a string attribute or remove the attribute.
    void setByte​(java.lang.String element, byte val)
    Set byte text in enclosing element.
    void setByteObject​(java.lang.String element, java.lang.Byte object)
    Set byte text in enclosing element or remove the element.
    void setDouble​(java.lang.String element, double val)
    Set double text in enclosing element.
    void setDoubleObject​(java.lang.String element, java.lang.Double object)
    Set double text in enclosing element or remove the element.
    void setFloat​(java.lang.String element, float val)
    Set float text in enclosing element.
    void setFloatObject​(java.lang.String element, java.lang.Float object)
    Set float text in enclosing element or remove the element.
    void setInt​(java.lang.String element, int val)
    Set int text in enclosing element.
    void setIntObject​(java.lang.String element, java.lang.Integer object)
    Set int text in enclosing element or remove the element.
    void setLong​(java.lang.String element, long val)
    Set long text in enclosing element.
    void setLongObject​(java.lang.String element, java.lang.Long object)
    Set long text in enclosing element or remove the element.
    void setRow​(java.lang.String element, XMLRowable rowable)
    Set a data structure in enclosing element.
    void setRowObject​(java.lang.String element, XMLRowable object)
    Set data structure in enclosing element or remove the element.
    void setShort​(java.lang.String element, short val)
    Set short text in enclosing element.
    void setShortObject​(java.lang.String element, java.lang.Short object)
    Set short text in enclosing element or remove the element.
    void setString​(java.lang.String element, java.lang.String object)
    Set text in enclosing element
    void setStringObject​(java.lang.String element, java.lang.String object)
    Set text in enclosing element or remove the element.
    void setThisByte​(byte val)
    Set byte text in this element.
    void setThisByteObject​(java.lang.Byte object)
    Set byte text in this element or remove the text contents.
    void setThisDouble​(double val)
    Set double text in this element.
    void setThisDoubleObject​(java.lang.Double object)
    Set double text in this element or remove the text contents.
    void setThisFloat​(float val)
    Set float text in this element.
    void setThisFloatObject​(java.lang.Float object)
    Set float text in this element or remove the text contents.
    void setThisInt​(int val)
    Set int text in this element.
    void setThisIntObject​(java.lang.Integer object)
    Set int text in this element or remove the text contents.
    void setThisLong​(long val)
    Set long text in this element.
    void setThisLongObject​(java.lang.Long object)
    Set long text in this element or remove the text contents.
    void setThisRow​(XMLRowable rowable)
    Set data structure in this element.
    void setThisRowObject​(XMLRowable object)
    Set data structure in this element or remove the contents.
    void setThisShort​(short val)
    Set short text in this element.
    void setThisShortObject​(java.lang.Short object)
    Set short text in this element or remove the text contents.
    void setThisString​(java.lang.String object)
    Set text in this element
    void setThisStringObject​(java.lang.String object)
    Set text in this element or remove the contents.
    void unparse​(XMLDocumentType document_type, java.io.OutputStream os)
    Convert the XML to a string representation.
    void unparse​(XMLDocumentType document_type, java.io.Writer w)
    Convert the XML to a string representation.
    void unparse​(XMLDocumentType document_type, javax.xml.transform.stream.StreamResult result)
    Convert the XML to a string representation.
    java.lang.String unparseToString​(XMLDocumentType document_type)
    Convert the XML to a string representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DocumentFragment

      public DocumentFragment​(java.lang.String tag)
      Construct an element with no children and no attributes.
      Parameters:
      tag - The XML tag of the element.
    • DocumentFragment

      public DocumentFragment​(java.lang.String tag, java.util.Map<java.lang.String,​java.lang.String> attributes)
      Construct an element with no children
      Parameters:
      tag - The XML tag of the element.
      attributes - The attributes of the element.
    • DocumentFragment

      public DocumentFragment​(java.lang.String tag, java.util.List<DocumentFragment> children)
      Construct an element with no attributes
      Parameters:
      tag - The XML tag of the element.
      children - The children of the element.
    • DocumentFragment

      public DocumentFragment​(java.lang.String tag, java.util.List<DocumentFragment> children, java.util.Map<java.lang.String,​java.lang.String> attributes)
      Construct an element
      Parameters:
      tag - The XML tag of the element.
      children - The children of the element.
      attributes - The attributes of the element.
  • Method Details

    • unparse

      public void unparse​(XMLDocumentType document_type, javax.xml.transform.stream.StreamResult result) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
      Convert the XML to a string representation.
      Parameters:
      document_type - XMLDocumentType.WHOLE or FRAGMENT
      result - The StreamResult
      Throws:
      javax.xml.parsers.ParserConfigurationException
      javax.xml.transform.TransformerConfigurationException
      javax.xml.transform.TransformerException
    • unparse

      public void unparse​(XMLDocumentType document_type, java.io.OutputStream os) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
      Convert the XML to a string representation.
      Parameters:
      document_type - XMLDocumentType.WHOLE or FRAGMENT
      os - An output stream
      Throws:
      javax.xml.parsers.ParserConfigurationException
      javax.xml.transform.TransformerConfigurationException
      javax.xml.transform.TransformerException
    • unparse

      public void unparse​(XMLDocumentType document_type, java.io.Writer w) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
      Convert the XML to a string representation.
      Parameters:
      document_type - XMLDocumentType.WHOLE or FRAGMENT
      w - A writer
      Throws:
      javax.xml.parsers.ParserConfigurationException
      javax.xml.transform.TransformerConfigurationException
      javax.xml.transform.TransformerException
    • unparseToString

      public java.lang.String unparseToString​(XMLDocumentType document_type) throws javax.xml.parsers.ParserConfigurationException, javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException
      Convert the XML to a string representation.
      Parameters:
      document_type - XMLDocumentType.WHOLE or FRAGMENT
      Returns:
      The string representation
      Throws:
      javax.xml.parsers.ParserConfigurationException
      javax.xml.transform.TransformerConfigurationException
      javax.xml.transform.TransformerException
    • convertToDomNode

      public org.w3c.dom.Node convertToDomNode​(org.w3c.dom.Document doc)
      Convert the XML to a DOM node.
      Parameters:
      doc - The DOM document
      Returns:
      The DOM node
    • getAttributes

      public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
      Get the attributes of the element. Note that text elements do not have attributes, so this will throw an exception if called for a text element. NB: the caller may modify the map of attributes, but may not add null keys or values to the map (this isn't enforced currently).
      Returns:
      modifiable attribute map
    • getChildren

      public java.util.List<DocumentFragment> getChildren()
      Get the children of the element. Note that text elements do not have children, so this will throw an exception if called for a text element. NB: the caller may modify the list of children, but may not add null elements to the list (this isn't enforced currently).
      Returns:
      modifiable children list
    • getNonTextChildren

      public java.util.List<DocumentFragment> getNonTextChildren()
      Get the non-text children of the element. Note that text elements do not have children, so this will throw an exception if called for a text element. NB: the returned list is an off-line copy; modifying it will have no effect.
      Returns:
      children list
    • setAttr

      public void setAttr​(java.lang.String attr, java.lang.String val)
      Deprecated.
      use setAttrString
      Convenience method for setting an attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrString

      public void setAttrString​(java.lang.String attr, java.lang.String val)
      Convenience method for setting an attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • removeAttr

      public void removeAttr​(java.lang.String attr)
      Convenience method for removing an attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
    • setAttrByte

      public void setAttrByte​(java.lang.String attr, byte val)
      Set a byte attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrShort

      public void setAttrShort​(java.lang.String attr, short val)
      Set a short attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrInt

      public void setAttrInt​(java.lang.String attr, int val)
      Set an int attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrLong

      public void setAttrLong​(java.lang.String attr, long val)
      Set a long attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrFloat

      public void setAttrFloat​(java.lang.String attr, float val)
      Set a float attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrDouble

      public void setAttrDouble​(java.lang.String attr, double val)
      Set a double attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value
    • setAttrByteObject

      public void setAttrByteObject​(java.lang.String attr, java.lang.Byte val)
      Set a byte attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • setAttrShortObject

      public void setAttrShortObject​(java.lang.String attr, java.lang.Short val)
      Set a short attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • setAttrIntObject

      public void setAttrIntObject​(java.lang.String attr, java.lang.Integer val)
      Set a int attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • setAttrLongObject

      public void setAttrLongObject​(java.lang.String attr, java.lang.Long val)
      Set a long attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • setAttrFloatObject

      public void setAttrFloatObject​(java.lang.String attr, java.lang.Float val)
      Set a float attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • setAttrDoubleObject

      public void setAttrDoubleObject​(java.lang.String attr, java.lang.Double val)
      Set a double attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • setAttrStringObject

      public void setAttrStringObject​(java.lang.String attr, java.lang.String val)
      Set a string attribute or remove the attribute. Note that text elements do not have attributes, so this will throw an exception if called for a text element.
      Parameters:
      attr - The attribute name
      val - The attribute value or null if the attribute is to be removed
    • addChild

      public void addChild​(DocumentFragment child)
      Deprecated.
      Use add(child)
      Convenience method for adding a child. Note that text elements do not have children, so this will throw an exception if called for a text element.
      Parameters:
      child - The child to be added
    • add

      public void add​(DocumentFragment child)
      Convenience method for adding a child. Note that text elements do not have children, so this will throw an exception if called for a text element.
      Parameters:
      child - The child to be added
    • add

      public DocumentFragment add​(java.lang.String tag)
      Convenience method for adding a child by tag name. Note that text elements do not have children, so this will throw an exception if called for a text element.
      Parameters:
      tag - The tag name
      Returns:
      The added child
    • addTextChild

      public void addTextChild​(java.lang.String text)
      Convenience method for adding a text child. Will coalesce multiple consecutive text children into one. Note that text elements do not have children, so this will throw an exception if called for a text element.
      Parameters:
      text - The text of the child to be added
    • isTextElement

      public boolean isTextElement()
      Test whether this element is a text element.
      Returns:
      Whether this is a text element
    • getText

      public java.lang.String getText()
      Return the text of the element. Returns null if called for a non-text element.
      Returns:
      The text of the element or null.
    • newText

      public static DocumentFragment newText​(java.lang.String text)
      Construct a text element.
      Parameters:
      text - The text of the text element.
    • getTag

      public java.lang.String getTag()
      Get the tag name of the element.
      Returns:
      The tag name or null for text elements
    • getMulti

      public java.util.ArrayList<DocumentFragment> getMulti​(java.lang.String tag)
      Get a list of children with the specified tag
      Parameters:
      tag - The specified tag
      Returns:
      The list of children with the specified tag
    • get

      public DocumentFragment get​(java.lang.String tag)
      Get the only child with the specified tag. If there are multiple children with the specified tag, throws an exception.
      Parameters:
      tag - The specified tag
      Returns:
      The child with the specified tag or null if no such child exists
    • getNotNull

      public DocumentFragment getNotNull​(java.lang.String tag)
      Get the only child with the specified tag, asserting it is non-null. If there are multiple children with the specified tag, throws an exception. If there is no child with the specified tag, throws an exception.
      Parameters:
      tag - The specified tag
      Returns:
      The child with the specified tag
    • assertTag

      public void assertTag​(java.lang.String tag)
      Assert that the tag name is the specified. If the tag name differs, throws an exception.
      Parameters:
      tag - The specified tag name
    • removeAll

      public java.util.List<DocumentFragment> removeAll()
      Remove and get a list of all children
      Returns:
      The list of children with the specified tag
    • removeMulti

      public java.util.ArrayList<DocumentFragment> removeMulti​(java.lang.String tag)
      Remove and get a list of children with the specified tag
      Parameters:
      tag - The specified tag
      Returns:
      The list of children with the specified tag
    • remove

      public DocumentFragment remove​(java.lang.String tag)
      Remove and get the only child with the specified tag. If there are multiple children with the specified tag, throws an exception and does not modify the list.
      Parameters:
      tag - The specified tag
      Returns:
      The child with the specified tag or null if no such child exists
    • getAttrByteNotNull

      public byte getAttrByteNotNull​(java.lang.String attr)
      Get a byte attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a byte
    • getAttrByte

      public byte getAttrByte​(java.lang.String attr, byte default_value)
      Get a byte attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as a byte
    • getAttrByteObject

      public java.lang.Byte getAttrByteObject​(java.lang.String attr)
      Get a byte attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a byte or null if nonexistent
    • getAttrShortNotNull

      public short getAttrShortNotNull​(java.lang.String attr)
      Get a short attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a short
    • getAttrShort

      public short getAttrShort​(java.lang.String attr, short default_value)
      Get a short attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as a short
    • getAttrShortObject

      public java.lang.Short getAttrShortObject​(java.lang.String attr)
      Get a short attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a short or null if nonexistent
    • getAttrIntNotNull

      public int getAttrIntNotNull​(java.lang.String attr)
      Get an integer attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as an integer
    • getAttrInt

      public int getAttrInt​(java.lang.String attr, int default_value)
      Get an integer attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as an integer
    • getAttrIntObject

      public java.lang.Integer getAttrIntObject​(java.lang.String attr)
      Get an integer attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as an integer or null if nonexistent
    • getAttrLongNotNull

      public long getAttrLongNotNull​(java.lang.String attr)
      Get a long attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a long
    • getAttrLong

      public long getAttrLong​(java.lang.String attr, long default_value)
      Get a long attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as a long
    • getAttrLongObject

      public java.lang.Long getAttrLongObject​(java.lang.String attr)
      Get a long attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a long or null if nonexistent
    • getAttrFloatNotNull

      public float getAttrFloatNotNull​(java.lang.String attr)
      Get a float attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a float
    • getAttrFloat

      public float getAttrFloat​(java.lang.String attr, float default_value)
      Get a float attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as a float
    • getAttrFloatObject

      public java.lang.Float getAttrFloatObject​(java.lang.String attr)
      Get a float attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a float or null if nonexistent
    • getAttrDoubleNotNull

      public double getAttrDoubleNotNull​(java.lang.String attr)
      Get a double attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a double
    • getAttrDouble

      public double getAttrDouble​(java.lang.String attr, double default_value)
      Get a double attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as a double
    • getAttrDoubleObject

      public java.lang.Double getAttrDoubleObject​(java.lang.String attr)
      Get a double attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a double or null if nonexistent
    • getAttrStringNotNull

      public java.lang.String getAttrStringNotNull​(java.lang.String attr)
      Get a string attribute that must be non-null. Throws an exception if the attribute does not exist.
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a string
    • getAttrString

      public java.lang.String getAttrString​(java.lang.String attr, java.lang.String default_value)
      Get a string attribute
      Parameters:
      attr - The attribute name
      default_value - Default value if the attribute does not exist
      Returns:
      The value of the attribute as a string
    • getAttrStringObject

      public java.lang.String getAttrStringObject​(java.lang.String attr)
      Get a string attribute or null
      Parameters:
      attr - The attribute name
      Returns:
      The value of the attribute as a string or null if nonexistent
    • getThisByteNotNull

      public byte getThisByteNotNull()
      Get a byte text that must be non-null in this element.
      Returns:
      The value of the text as a byte
    • getThisByte

      public byte getThisByte​(byte default_value)
      Get a byte text in this element.
      Parameters:
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a byte
    • getThisByteObject

      public java.lang.Byte getThisByteObject()
      Get a byte text in this element or null.
      Returns:
      The value of the text as a byte
    • getThisShortNotNull

      public short getThisShortNotNull()
      Get a short text that must be non-null in this element.
      Returns:
      The value of the text as a short
    • getThisShort

      public short getThisShort​(short default_value)
      Get a short text in this element.
      Parameters:
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a short
    • getThisShortObject

      public java.lang.Short getThisShortObject()
      Get a short text in this element or null.
      Returns:
      The value of the text as a short
    • getThisIntNotNull

      public int getThisIntNotNull()
      Get an integer text that must be non-null in this element.
      Returns:
      The value of the text as an integer
    • getThisInt

      public int getThisInt​(int default_value)
      Get an integer text in this element.
      Parameters:
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as an integer
    • getThisIntObject

      public java.lang.Integer getThisIntObject()
      Get an integer text in this element or null.
      Returns:
      The value of the text as an integer
    • getThisLongNotNull

      public long getThisLongNotNull()
      Get a long text that must be non-null in this element.
      Returns:
      The value of the text as a long
    • getThisLong

      public long getThisLong​(long default_value)
      Get a long text in this element.
      Parameters:
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a long
    • getThisLongObject

      public java.lang.Long getThisLongObject()
      Get a long text in this element or null.
      Returns:
      The value of the text as a long
    • getThisFloatNotNull

      public float getThisFloatNotNull()
      Get a float text that must be non-null in this element.
      Returns:
      The value of the text as a float
    • getThisFloat

      public float getThisFloat​(float default_value)
      Get a float text in this element.
      Parameters:
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a float
    • getThisFloatObject

      public java.lang.Float getThisFloatObject()
      Get a float text in this element or null.
      Returns:
      The value of the text as a float
    • getThisDoubleNotNull

      public double getThisDoubleNotNull()
      Get a double text that must be non-null in this element.
      Returns:
      The value of the text as a double
    • getThisDouble

      public double getThisDouble​(double default_value)
      Get a double text in this element.
      Parameters:
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a double
    • getThisDoubleObject

      public java.lang.Double getThisDoubleObject()
      Get a double text in this element or null.
      Returns:
      The value of the text as a double
    • getThisString

      public java.lang.String getThisString​(java.lang.String default_value)
      Get text in this element.
      Parameters:
      default_value - Default value if the text is empty
      Returns:
      The value of the text as a string
    • getThisStringNotEmpty

      public java.lang.String getThisStringNotEmpty()
      Get text in this element that must be non-empty. Throws XMLValueMissingException if the contents are empty.
      Returns:
      The value of the text as a string
    • getThisStringObjectEmptyIsNull

      public java.lang.String getThisStringObjectEmptyIsNull()
      Get text in this element or null. Treats empty string content as null.
      Returns:
      The value of the text as a string
    • getThisStringObjectEmptyIsEmpty

      public java.lang.String getThisStringObjectEmptyIsEmpty()
      Get text in this element. Returns "" if the content is empty.
      Returns:
      The value of the text as a string
    • getByteNotNull

      public byte getByteNotNull​(java.lang.String element)
      Get a byte text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a byte
    • getByte

      public byte getByte​(java.lang.String element, byte default_value)
      Get a byte text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a byte
    • getByteObject

      public java.lang.Byte getByteObject​(java.lang.String element)
      Get a byte text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a byte
    • getShortNotNull

      public short getShortNotNull​(java.lang.String element)
      Get a short text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a short
    • getShort

      public short getShort​(java.lang.String element, short default_value)
      Get a short text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a short
    • getShortObject

      public java.lang.Short getShortObject​(java.lang.String element)
      Get a short text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a short
    • getIntNotNull

      public int getIntNotNull​(java.lang.String element)
      Get an integer text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as an integer
    • getInt

      public int getInt​(java.lang.String element, int default_value)
      Get an integer text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as an integer
    • getIntObject

      public java.lang.Integer getIntObject​(java.lang.String element)
      Get an integer text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as an integer
    • getLongNotNull

      public long getLongNotNull​(java.lang.String element)
      Get a long text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a long
    • getLong

      public long getLong​(java.lang.String element, long default_value)
      Get a long text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a long
    • getLongObject

      public java.lang.Long getLongObject​(java.lang.String element)
      Get a long text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a long
    • getFloatNotNull

      public float getFloatNotNull​(java.lang.String element)
      Get a float text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a float
    • getFloat

      public float getFloat​(java.lang.String element, float default_value)
      Get a float text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a float
    • getFloatObject

      public java.lang.Float getFloatObject​(java.lang.String element)
      Get a float text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a float
    • getDoubleNotNull

      public double getDoubleNotNull​(java.lang.String element)
      Get a double text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a double
    • getDouble

      public double getDouble​(java.lang.String element, double default_value)
      Get a double text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a double
    • getDoubleObject

      public java.lang.Double getDoubleObject​(java.lang.String element)
      Get a double text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a double
    • getStringNotNull

      public java.lang.String getStringNotNull​(java.lang.String element)
      Get text that must be non-null in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a string
    • getString

      public java.lang.String getString​(java.lang.String element, java.lang.String default_value)
      Get text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      default_value - Default value if the element does not exist
      Returns:
      The value of the text as a string
    • getStringObject

      public java.lang.String getStringObject​(java.lang.String element)
      Get text in enclosing element or null.
      Parameters:
      element - The tag of the enclosing element
      Returns:
      The value of the text as a string
    • setByte

      public void setByte​(java.lang.String element, byte val)
      Set byte text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      val - The value that will be converted to text
    • setShort

      public void setShort​(java.lang.String element, short val)
      Set short text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      val - The value that will be converted to text
    • setInt

      public void setInt​(java.lang.String element, int val)
      Set int text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      val - The value that will be converted to text
    • setLong

      public void setLong​(java.lang.String element, long val)
      Set long text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      val - The value that will be converted to text
    • setFloat

      public void setFloat​(java.lang.String element, float val)
      Set float text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      val - The value that will be converted to text
    • setDouble

      public void setDouble​(java.lang.String element, double val)
      Set double text in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      val - The value that will be converted to text
    • setRow

      public void setRow​(java.lang.String element, XMLRowable rowable)
      Set a data structure in enclosing element.
      Parameters:
      element - The tag of the enclosing element
      rowable - The value that will be serialized
    • setByteObject

      public void setByteObject​(java.lang.String element, java.lang.Byte object)
      Set byte text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be converted to text or null if the element is to be removed
    • setShortObject

      public void setShortObject​(java.lang.String element, java.lang.Short object)
      Set short text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be converted to text or null if the element is to be removed
    • setIntObject

      public void setIntObject​(java.lang.String element, java.lang.Integer object)
      Set int text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be converted to text or null if the element is to be removed
    • setLongObject

      public void setLongObject​(java.lang.String element, java.lang.Long object)
      Set long text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be converted to text or null if the element is to be removed
    • setFloatObject

      public void setFloatObject​(java.lang.String element, java.lang.Float object)
      Set float text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be converted to text or null if the element is to be removed
    • setDoubleObject

      public void setDoubleObject​(java.lang.String element, java.lang.Double object)
      Set double text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be converted to text or null if the element is to be removed
    • setRowObject

      public void setRowObject​(java.lang.String element, XMLRowable object)
      Set data structure in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The value that will be serialized or null if the element is to be removed
    • setThisByte

      public void setThisByte​(byte val)
      Set byte text in this element.
      Parameters:
      val - The value that will be converted to text
    • setThisShort

      public void setThisShort​(short val)
      Set short text in this element.
      Parameters:
      val - The value that will be converted to text
    • setThisInt

      public void setThisInt​(int val)
      Set int text in this element.
      Parameters:
      val - The value that will be converted to text
    • setThisLong

      public void setThisLong​(long val)
      Set long text in this element.
      Parameters:
      val - The value that will be converted to text
    • setThisFloat

      public void setThisFloat​(float val)
      Set float text in this element.
      Parameters:
      val - The value that will be converted to text
    • setThisDouble

      public void setThisDouble​(double val)
      Set double text in this element.
      Parameters:
      val - The value that will be converted to text
    • setThisRow

      public void setThisRow​(XMLRowable rowable)
      Set data structure in this element.
      Parameters:
      rowable - The value that will be serialized
    • setThisByteObject

      public void setThisByteObject​(java.lang.Byte object)
      Set byte text in this element or remove the text contents.
      Parameters:
      object - The value that will be converted to text or null if the text contents are to be removed
    • setThisShortObject

      public void setThisShortObject​(java.lang.Short object)
      Set short text in this element or remove the text contents.
      Parameters:
      object - The value that will be converted to text or null if the text contents are to be removed
    • setThisIntObject

      public void setThisIntObject​(java.lang.Integer object)
      Set int text in this element or remove the text contents.
      Parameters:
      object - The value that will be converted to text or null if the text contents are to be removed
    • setThisLongObject

      public void setThisLongObject​(java.lang.Long object)
      Set long text in this element or remove the text contents.
      Parameters:
      object - The value that will be converted to text or null if the text contents are to be removed
    • setThisFloatObject

      public void setThisFloatObject​(java.lang.Float object)
      Set float text in this element or remove the text contents.
      Parameters:
      object - The value that will be converted to text or null if the text contents are to be removed
    • setThisDoubleObject

      public void setThisDoubleObject​(java.lang.Double object)
      Set double text in this element or remove the text contents.
      Parameters:
      object - The value that will be converted to text or null if the text contents are to be removed
    • setThisRowObject

      public void setThisRowObject​(XMLRowable object)
      Set data structure in this element or remove the contents.
      Parameters:
      object - The value that will be serialized or null if the contents are to be removed
    • getOrCreate

      public DocumentFragment getOrCreate​(java.lang.String element)
      Return the element with the tag name, creating it if nonexistent.
      Parameters:
      element - The tag of the element
      Returns:
      The element
    • set

      public DocumentFragment set​(java.lang.String element)
      Return the element with the tag name, creating it if nonexistent and clear its contents if existent.
      Parameters:
      element - The tag of the element
      Returns:
      The element
    • setString

      public void setString​(java.lang.String element, java.lang.String object)
      Set text in enclosing element
      Parameters:
      element - The tag of the enclosing element
      object - The text in enclosing element
    • setStringObject

      public void setStringObject​(java.lang.String element, java.lang.String object)
      Set text in enclosing element or remove the element.
      Parameters:
      element - The tag of the enclosing element
      object - The text in enclosing element or null if the element is to be removed
    • setThisString

      public void setThisString​(java.lang.String object)
      Set text in this element
      Parameters:
      object - The text in enclosing element or null if the element is to be removed
    • setThisStringObject

      public void setThisStringObject​(java.lang.String object)
      Set text in this element or remove the contents.
      Parameters:
      object - The text in enclosing element or null if the contents are to be removed