nanoxml
Class XMLElement

java.lang.Object
  |
  +--nanoxml.XMLElement

public class XMLElement
extends java.lang.Object

XMLElement is a representation of an XML object. The object is able to parse XML code.

Version:
$Name: $, $Revision: 1.1.1.1 $
Author:
Marc De Scheemaecker
See Also:
XMLParseException

Field Summary
static int NANOXML_MAJOR_VERSION
          Major version of NanoXML.
static int NANOXML_MINOR_VERSION
          Minor version of NanoXML.
 
Constructor Summary
XMLElement()
          Creates a new XML element.
XMLElement(boolean skipLeadingWhitespace)
          Creates a new XML element.
XMLElement(java.util.Hashtable entities)
          Creates a new XML element.
XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace)
          Creates a new XML element.
XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)
          Creates a new XML element.
 
Method Summary
 void addChild(XMLElement child)
          Adds a subobject.
 void addProperty(java.lang.String key, double value)
          Adds a property.
 void addProperty(java.lang.String key, int value)
          Adds a property.
 void addProperty(java.lang.String key, java.lang.Object value)
          Adds a property.
 int countChildren()
          Returns the number of subobjects of the object.
 java.util.Enumeration enumerateChildren()
          Enumerates the subobjects of the object.
 java.util.Enumeration enumeratePropertyNames()
          Enumerates the attribute names.
 java.util.Vector getChildren()
          Returns the subobjects of the object.
 java.lang.String getContents()
          Returns the #PCDATA content of the object.
 int getIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
          Returns a property by looking up a key in a hashtable.
 int getLineNr()
          Returns the line nr on which the element is found.
 java.lang.String getName()
          Returns the class (i.e.
 java.lang.String getProperty(java.lang.String key)
          Returns a property of the object.
 double getProperty(java.lang.String key, double defaultValue)
          Returns a floating point property of the object.
 java.lang.Object getProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
          Returns a property by looking up a key in the hashtable valueSet If the property doesn't exist, the value corresponding to defaultValue is returned.
 int getProperty(java.lang.String key, int defaultValue)
          Returns an integer property of the object.
 java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
          Returns a property of the object.
 boolean getProperty(java.lang.String key, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)
          Returns a boolean property of the object.
 double getSpecialDoubleProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
          Returns a property by looking up a key in the hashtable valueSet.
 int getSpecialIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
          Returns a property by looking up a key in the hashtable valueSet.
 java.lang.String getStringProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
          Returns a property by looking up a key in the hashtable valueSet.
 java.lang.String getTagName()
          Deprecated. Use getName instead.
 void parseCharArray(char[] input, int offset, int end)
          Parses an XML definition starting at offset.
 void parseCharArray(char[] input, int offset, int end, int startingLineNr)
          Parses an XML definition starting at offset.
 void parseFromReader(java.io.Reader reader)
          Reads an XML definition from a java.io.Reader and parses it.
 void parseFromReader(java.io.Reader reader, int startingLineNr)
          Reads an XML definition from a java.io.Reader and parses it.
 void parseString(java.lang.String string)
          Parses an XML definition.
 void parseString(java.lang.String string, int offset)
          Parses an XML definition starting at offset.
 void parseString(java.lang.String string, int offset, int end)
          Parses an XML definition starting at offset.
 void parseString(java.lang.String string, int offset, int end, int startingLineNr)
          Parses an XML definition starting at offset.
 void removeChild(java.lang.String key)
          Removes an attribute.
 void removeChild(XMLElement child)
          Removes a child object.
 void setContent(java.lang.String content)
          Changes the content string.
 void setName(java.lang.String name)
          Changes the element name.
 void setTagName(java.lang.String name)
          Deprecated. Use setName instead.
 java.lang.String toString()
          Writes the XML element to a string.
 void write(java.io.Writer writer)
          Writes the XML element to a writer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NANOXML_MAJOR_VERSION

public static final int NANOXML_MAJOR_VERSION
Major version of NanoXML.

NANOXML_MINOR_VERSION

public static final int NANOXML_MINOR_VERSION
Minor version of NanoXML.
Constructor Detail

XMLElement

public XMLElement()
Creates a new XML element. The following settings are used:
Conversion table
Minimal XML conversions: & < > ' "
Skip whitespace in contents
false
Ignore Case
true
See Also:
XMLElement(java.util.Hashtable), XMLElement(boolean), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(java.util.Hashtable entities)
Creates a new XML element. The following settings are used:
Conversion table
entities combined with the minimal XML conversions: & < > ' "
Skip whitespace in contents
false
Ignore Case
true
See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(boolean skipLeadingWhitespace)
Creates a new XML element. The following settings are used:
Conversion table
Minimal XML conversions: & < > ' "
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
true
See Also:
XMLElement(), XMLElement(java.util.Hashtable), XMLElement(java.util.Hashtable,boolean)

XMLElement

public XMLElement(java.util.Hashtable entities,
                  boolean skipLeadingWhitespace)
Creates a new XML element. The following settings are used:
Conversion table
entities combined with the minimal XML conversions: & < > ' "
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
true
See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable)

XMLElement

public XMLElement(java.util.Hashtable entities,
                  boolean skipLeadingWhitespace,
                  boolean ignoreCase)
Creates a new XML element. The following settings are used:
Conversion table
entities, eventually combined with the minimal XML conversions: & < > ' " (depending on fillBasicConversionTable)
Skip whitespace in contents
skipLeadingWhitespace
Ignore Case
ignoreCase

This constructor should only be called from XMLElement itself to create child elements.

See Also:
XMLElement(), XMLElement(boolean), XMLElement(java.util.Hashtable), XMLElement(java.util.Hashtable,boolean)
Method Detail

addChild

public void addChild(XMLElement child)
Adds a subobject.

addProperty

public void addProperty(java.lang.String key,
                        java.lang.Object value)
Adds a property.

addProperty

public void addProperty(java.lang.String key,
                        int value)
Adds a property.

addProperty

public void addProperty(java.lang.String key,
                        double value)
Adds a property.

countChildren

public int countChildren()
Returns the number of subobjects of the object.

enumeratePropertyNames

public java.util.Enumeration enumeratePropertyNames()
Enumerates the attribute names.

enumerateChildren

public java.util.Enumeration enumerateChildren()
Enumerates the subobjects of the object.

getChildren

public java.util.Vector getChildren()
Returns the subobjects of the object.

getContents

public java.lang.String getContents()
Returns the #PCDATA content of the object. If there is no such content, null is returned.

getLineNr

public int getLineNr()
Returns the line nr on which the element is found.

getIntProperty

public int getIntProperty(java.lang.String key,
                          java.util.Hashtable valueSet,
                          java.lang.String defaultValue)
Returns a property by looking up a key in a hashtable. If the property doesn't exist, the value corresponding to defaultValue is returned.

getProperty

public java.lang.String getProperty(java.lang.String key)
Returns a property of the object. If there is no such property, this method returns null.

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defaultValue)
Returns a property of the object. If the property doesn't exist, defaultValue is returned.

getProperty

public int getProperty(java.lang.String key,
                       int defaultValue)
Returns an integer property of the object. If the property doesn't exist, defaultValue is returned.

getProperty

public double getProperty(java.lang.String key,
                          double defaultValue)
Returns a floating point property of the object. If the property doesn't exist, defaultValue is returned.

getProperty

public boolean getProperty(java.lang.String key,
                           java.lang.String trueValue,
                           java.lang.String falseValue,
                           boolean defaultValue)
Returns a boolean property of the object. If the property is missing, defaultValue is returned.

getProperty

public java.lang.Object getProperty(java.lang.String key,
                                    java.util.Hashtable valueSet,
                                    java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet If the property doesn't exist, the value corresponding to defaultValue is returned.

getStringProperty

public java.lang.String getStringProperty(java.lang.String key,
                                          java.util.Hashtable valueSet,
                                          java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet. If the property doesn't exist, the value corresponding to defaultValue is returned.

getSpecialIntProperty

public int getSpecialIntProperty(java.lang.String key,
                                 java.util.Hashtable valueSet,
                                 java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet. If the value is not defined in the hashtable, the value is considered to be an integer. If the property doesn't exist, the value corresponding to defaultValue is returned.

getSpecialDoubleProperty

public double getSpecialDoubleProperty(java.lang.String key,
                                       java.util.Hashtable valueSet,
                                       java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet. If the value is not defined in the hashtable, the value is considered to be a floating point number. If the property doesn't exist, the value corresponding to defaultValue is returned.

getName

public java.lang.String getName()
Returns the class (i.e. the name indicated in the element) of the object.

getTagName

public java.lang.String getTagName()
Deprecated. Use getName instead.

Returns the class (i.e. the name indicated in the element) of the object.

parseFromReader

public void parseFromReader(java.io.Reader reader)
                     throws java.io.IOException,
                            XMLParseException
Reads an XML definition from a java.io.Reader and parses it.
Throws:
java.io.IOException - if an error occured while reading the input
XMLParseException - if an error occured while parsing the read data

parseFromReader

public void parseFromReader(java.io.Reader reader,
                            int startingLineNr)
                     throws java.io.IOException,
                            XMLParseException
Reads an XML definition from a java.io.Reader and parses it.
Throws:
java.io.IOException - if an error occured while reading the input
XMLParseException - if an error occured while parsing the read data

parseString

public void parseString(java.lang.String string)
                 throws XMLParseException
Parses an XML definition.
Throws:
XMLParseException - if an error occured while parsing the string

parseString

public void parseString(java.lang.String string,
                        int offset)
                 throws XMLParseException
Parses an XML definition starting at offset.
Throws:
XMLParseException - if an error occured while parsing the string

parseString

public void parseString(java.lang.String string,
                        int offset,
                        int end)
                 throws XMLParseException
Parses an XML definition starting at offset.
Throws:
XMLParseException - if an error occured while parsing the string

parseString

public void parseString(java.lang.String string,
                        int offset,
                        int end,
                        int startingLineNr)
                 throws XMLParseException
Parses an XML definition starting at offset.
Throws:
XMLParseException - if an error occured while parsing the string

parseCharArray

public void parseCharArray(char[] input,
                           int offset,
                           int end)
                    throws XMLParseException
Parses an XML definition starting at offset.
Throws:
XMLParseException - if an error occured while parsing the array

parseCharArray

public void parseCharArray(char[] input,
                           int offset,
                           int end,
                           int startingLineNr)
                    throws XMLParseException
Parses an XML definition starting at offset.
Throws:
XMLParseException - if an error occured while parsing the array

removeChild

public void removeChild(XMLElement child)
Removes a child object. If the object is not a child, nothing happens.

removeChild

public void removeChild(java.lang.String key)
Removes an attribute.

setContent

public void setContent(java.lang.String content)
Changes the content string.
Parameters:
content - The new content string.

setTagName

public void setTagName(java.lang.String name)
Deprecated. Use setName instead.

Changes the element name.
Parameters:
name - The new name.

setName

public void setName(java.lang.String name)
Changes the element name.
Parameters:
name - The new name.

toString

public java.lang.String toString()
Writes the XML element to a string.
Overrides:
toString in class java.lang.Object

write

public void write(java.io.Writer writer)
           throws java.io.IOException
Writes the XML element to a writer.