Class XMLElement

java.lang.Object
de.stefanfrings.utils.XMLElement

public class XMLElement extends Object
Storage container for one single XML element, used by SimpleXMLParser.
Author:
Stefan Frings, http://stefanfrings.de/javautils
  • Field Details

    • shortName

      public final String shortName
      Name of this element as written in the XML file. For example, if the fullname is "music/pop/prince" then the short name is "prince".
    • fullName

      public final String fullName
      Hierarchical name of this element.

      For example, if the shortname of this element is "prince", which is a sub-element of "pop" which is a sub-element of "music", then the fullname would be "music/pop/prince".

    • parent

      public final XMLElement parent
      Link to the parent element, null if this is the root element
  • Constructor Details

    • XMLElement

      public XMLElement(String shortName, String fullName, XMLElement parent)
      Constructor
      Parameters:
      shortName - short name of the element
      fullName - full name of the element
      parent - Parent element or null.
  • Method Details

    • toString

      public String toString()
      Returns the data of this object in human readable format.
      Overrides:
      toString in class Object
      Returns:
      a String
    • setAttribute

      public void setAttribute(String name, String value)
      Sets an attribute. If the value is null, the attribute gets removed.
      Parameters:
      name - name
      value - value
    • addCharacters

      protected void addCharacters(char[] ch, int start, int length)
      Append characters to the character buffer.
      Parameters:
      ch - Buffer of characters to be added
      start - position of first character in the buffer
      length - length of the buffer
    • charactersToMap

      protected void charactersToMap()
      Trim and copy the characters to the internal map.
    • getAttribute

      public String getAttribute(String name)
      Gets an attribute.
      Parameters:
      name - Name of the attribute
      Returns:
      The attributes value or null if no such attribute exists.
    • getAttribute

      public String getAttribute(String name, String defaultValue)
      Gets an attribute.
      Parameters:
      name - Name of the attribute
      defaultValue - Default value, used if the attribute is not set.
      Returns:
      The attributes value or the default value.
    • allowedAttributes

      public void allowedAttributes(String... allowedNames) throws Exception
      Checks if the element has any unexpected attributes.
      Parameters:
      allowedNames - The names of the allowed attributes.
      Throws:
      Exception - if the element has unexpected attributes.
    • requiredAttributes

      public void requiredAttributes(String... requiredNames) throws Exception
      Checks if the element has all required attributes.
      Parameters:
      requiredNames - The names of the required attributes.
      Throws:
      Exception - if an attribute is missing