Class XMLElement

  • public class XMLElement
    extends Object
    Storage container for one single XML element, used by SimpleXMLParser.
    Stefan Frings,
    • Field Detail

      • 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 Detail

      • XMLElement

        public XMLElement​(String shortName,
                          String fullName,
                          XMLElement parent)
        shortName - short name of the element
        fullName - full name of the element
        parent - Parent element or null.
    • Method Detail

      • toString

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

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

        protected void addCharacters​(char[] ch,
                                     int start,
                                     int length)
        Append characters to the character buffer.
        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.
        name - Name of the attribute
        The attributes value or null if no such attribute exists.
      • getAttribute

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

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

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