Package de.stefanfrings.utils
Class XMLElement
java.lang.Object
de.stefanfrings.utils.XMLElement
Storage container for one single XML element, used by
SimpleXMLParser.- Author:
- Stefan Frings, http://stefanfrings.de/javautils
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXMLElement(String shortName, String fullName, XMLElement parent) Constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCharacters(char[] ch, int start, int length) Append characters to the character buffer.voidallowedAttributes(String... allowedNames) Checks if the element has any unexpected attributes.protected voidTrim and copy the characters to the internal map.getAttribute(String name) Gets an attribute.getAttribute(String name, String defaultValue) Gets an attribute.voidrequiredAttributes(String... requiredNames) Checks if the element has all required attributes.voidsetAttribute(String name, String value) Sets an attribute.toString()Returns the data of this object in human readable format.
-
Field Details
-
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
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
Link to the parent element, null if this is the root element
-
-
Constructor Details
-
XMLElement
Constructor- Parameters:
shortName- short name of the elementfullName- full name of the elementparent- Parent element or null.
-
-
Method Details
-
toString
Returns the data of this object in human readable format. -
setAttribute
Sets an attribute. If the value is null, the attribute gets removed.- Parameters:
name- namevalue- value
-
addCharacters
protected void addCharacters(char[] ch, int start, int length) Append characters to the character buffer.- Parameters:
ch- Buffer of characters to be addedstart- position of first character in the bufferlength- length of the buffer
-
charactersToMap
protected void charactersToMap()Trim and copy the characters to the internal map. -
getAttribute
Gets an attribute.- Parameters:
name- Name of the attribute- Returns:
- The attributes value or null if no such attribute exists.
-
getAttribute
Gets an attribute.- Parameters:
name- Name of the attributedefaultValue- Default value, used if the attribute is not set.- Returns:
- The attributes value or the default value.
-
allowedAttributes
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
Checks if the element has all required attributes.- Parameters:
requiredNames- The names of the required attributes.- Throws:
Exception- if an attribute is missing
-