freemind.main

Class XMLElement

public class XMLElement extends Object

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

Parsing XML Data
You can parse XML data using the following code:
    XMLElement xml = new XMLElement();
    FileReader reader = new FileReader("filename.xml");
    xml.parseFromReader(reader);
Retrieving Attributes
You can enumerate the attributes of an element using the method enumerateAttributeNames. The attribute values can be retrieved using the method getStringAttribute. The following example shows how to list the attributes of an element:
    XMLElement element = ...;
    Enumeration enum = element.getAttributeNames();
    while (enum.hasMoreElements()) {
        String key = (String) enum.nextElement();
        String value = element.getStringAttribute(key);
        System.out.println(key + " = " + value);
    }
Retrieving Child Elements
You can enumerate the children of an element using enumerateChildren. The number of child elements can be retrieved using countChildren.
Elements Containing Character Data
If an elements contains character data, like in the following example:
    <title>The Title</title>
you can retrieve that data using the method getContent.
Subclassing XMLElement
When subclassing XMLElement, you need to override the method createAnotherElement which has to return a new copy of the receiver.

Version: $Name: FM-0-7-1 $, $Revision: 1.7 $

Author: Marc De Scheemaecker <cyberelf@mac.com>

See Also: nanoxml.XMLParseException

Field Summary
protected booleanignoreCase
true if the case of the element and attribute names are case insensitive.
static intNANOXML_MAJOR_VERSION
Major version of NanoXML.
static intNANOXML_MINOR_VERSION
Minor version of NanoXML.
Constructor Summary
XMLElement()
Creates and initializes a new XML element.
XMLElement(Hashtable entities)
Creates and initializes a new XML element.
XMLElement(boolean skipLeadingWhitespace)
Creates and initializes a new XML element.
XMLElement(Hashtable entities, boolean skipLeadingWhitespace)
Creates and initializes a new XML element.
XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)
Creates and initializes a new XML element.
protected XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)
Creates and initializes a new XML element.
Method Summary
voidaddChild(XMLElement child)
Adds a child element.
voidaddProperty(String name, Object value)
Adds or modifies an attribute.
voidaddProperty(String key, int value)
Adds or modifies an attribute.
voidaddProperty(String name, double value)
Adds or modifies an attribute.
protected booleancheckCDATA(StringBuffer buf)
Scans a special tag and if the tag is a CDATA section, append its content to buf.
protected booleancheckLiteral(String literal)
Scans the data for literal text.
protected voidcompleteElement()
intcountChildren()
Returns the number of child elements of the element.
protected XMLElementcreateAnotherElement()
Creates a new similar XML element.
EnumerationenumerateAttributeNames()
Enumerates the attribute names.
EnumerationenumerateChildren()
Enumerates the child elements.
EnumerationenumeratePropertyNames()
Enumerates the attribute names.
protected XMLParseExceptionexpectedInput(String charSet)
Creates a parse exception for when the next character read is not the character that was expected.
ObjectgetAttribute(String name)
Returns an attribute of the element.
ObjectgetAttribute(String name, Object defaultValue)
Returns an attribute of the element.
ObjectgetAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals)
Returns an attribute by looking up a key in a hashtable.
booleangetBooleanAttribute(String name, String trueValue, String falseValue, boolean defaultValue)
Returns an attribute of the element.
VectorgetChildren()
Returns the child elements as a Vector.
StringgetContent()
Returns the PCDATA content of the object.
StringgetContents()
Returns the PCDATA content of the object.
doublegetDoubleAttribute(String name)
Returns an attribute of the element.
doublegetDoubleAttribute(String name, double defaultValue)
Returns an attribute of the element.
doublegetDoubleAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiteralNumbers)
Returns an attribute by looking up a key in a hashtable.
intgetIntAttribute(String name)
Returns an attribute of the element.
intgetIntAttribute(String name, int defaultValue)
Returns an attribute of the element.
intgetIntAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiteralNumbers)
Returns an attribute by looking up a key in a hashtable.
intgetIntProperty(String name, Hashtable valueSet, String defaultKey)
Returns an attribute by looking up a key in a hashtable.
intgetLineNr()
Returns the line nr in the source data on which the element is found.
StringgetName()
Returns the name of the element.
StringgetProperty(String name)
Returns an attribute.
StringgetProperty(String name, String defaultValue)
Returns an attribute.
intgetProperty(String name, int defaultValue)
Returns an attribute.
doublegetProperty(String name, double defaultValue)
Returns an attribute.
booleangetProperty(String key, String trueValue, String falseValue, boolean defaultValue)
Returns an attribute.
ObjectgetProperty(String name, Hashtable valueSet, String defaultKey)
Returns an attribute by looking up a key in a hashtable.
doublegetSpecialDoubleProperty(String name, Hashtable valueSet, String defaultKey)
Returns an attribute by looking up a key in a hashtable.
intgetSpecialIntProperty(String name, Hashtable valueSet, String defaultKey)
Returns an attribute by looking up a key in a hashtable.
StringgetStringAttribute(String name)
Returns an attribute of the element.
StringgetStringAttribute(String name, String defaultValue)
Returns an attribute of the element.
StringgetStringAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals)
Returns an attribute by looking up a key in a hashtable.
StringgetStringProperty(String name, Hashtable valueSet, String defaultKey)
Returns an attribute by looking up a key in a hashtable.
StringgetTagName()
Returns the name of the element.
ObjectgetUserObject()
protected XMLParseExceptioninvalidValue(String name, String value)
Creates a parse exception for when an invalid value is given to a method.
protected XMLParseExceptioninvalidValueSet(String name)
Creates a parse exception for when an invalid valueset is given to a method.
voidparseCharArray(char[] input, int offset, int end)
Reads one XML element from a char array and parses it.
voidparseCharArray(char[] input, int offset, int end, int startingLineNr)
Reads one XML element from a char array and parses it.
voidparseFromReader(Reader reader)
Reads one XML element from a java.io.Reader and parses it.
voidparseFromReader(Reader reader, int startingLineNr)
Reads one XML element from a java.io.Reader and parses it.
voidparseString(String string)
Reads one XML element from a String and parses it.
voidparseString(String string, int offset)
Reads one XML element from a String and parses it.
voidparseString(String string, int offset, int end)
Reads one XML element from a String and parses it.
voidparseString(String string, int offset, int end, int startingLineNr)
Reads one XML element from a String and parses it.
protected charreadChar()
Reads a character from a reader.
voidremoveAttribute(String name)
Removes an attribute.
voidremoveChild(XMLElement child)
Removes a child element.
voidremoveChild(String name)
Removes an attribute.
voidremoveProperty(String name)
Removes an attribute.
protected voidresolveEntity(StringBuffer buf)
Resolves an entity.
protected voidscanElement(XMLElement elt)
Scans an XML element.
protected voidscanIdentifier(StringBuffer result)
Scans an identifier from the current reader.
protected voidscanPCData(StringBuffer data)
Scans a #PCDATA element.
protected voidscanString(StringBuffer string)
This method scans a delimited string from the current reader.
protected charscanWhitespace()
This method scans an identifier from the current reader.
protected charscanWhitespace(StringBuffer result)
This method scans an identifier from the current reader.
voidsetAttribute(String name, Object value)
Adds or modifies an attribute.
voidsetContent(String content)
Changes the content string.
voidsetDoubleAttribute(String name, double value)
Adds or modifies an attribute.
voidsetIntAttribute(String name, int value)
Adds or modifies an attribute.
voidsetName(String name)
Changes the name of the element.
voidsetTagName(String name)
Changes the name of the element.
protected voidskipComment()
Skips a comment.
protected voidskipSpecialTag(int bracketLevel)
Skips a special tag or comment.
protected XMLParseExceptionsyntaxError(String context)
Creates a parse exception for when a syntax error occured.
StringtoString()
Writes the XML element to a string.
protected XMLParseExceptionunexpectedEndOfData()
Creates a parse exception for when the end of the data input has been reached.
protected XMLParseExceptionunknownEntity(String name)
Creates a parse exception for when an entity could not be resolved.
protected voidunreadChar(char ch)
Pushes a character back to the read-back buffer.
voidwrite(Writer writer)
Writes the XML element to a writer.
voidwrite(Writer writer, boolean withClosingTag)
voidwriteClosingTag(Writer writer)
protected voidwriteEncoded(Writer writer, String str)
Writes a string encoded to a writer.
voidwriteWithoutClosingTag(Writer writer)

Field Detail

ignoreCase

protected boolean ignoreCase
true if the case of the element and attribute names are case insensitive.

NANOXML_MAJOR_VERSION

public static final int NANOXML_MAJOR_VERSION
Major version of NanoXML. Classes with the same major and minor version are binary compatible. Classes with the same major version are source compatible. If the major version is different, you may need to modify the client source code.

See Also: nanoxml.XMLElement#NANOXML_MINOR_VERSION

NANOXML_MINOR_VERSION

public static final int NANOXML_MINOR_VERSION
Minor version of NanoXML. Classes with the same major and minor version are binary compatible. Classes with the same major version are source compatible. If the major version is different, you may need to modify the client source code.

See Also: nanoxml.XMLElement#NANOXML_MAJOR_VERSION

Constructor Detail

XMLElement

public XMLElement()
Creates and initializes a new XML element. Calling the construction is equivalent to:
Postconditions:
  • countChildren() => 0
  • enumerateChildren() => empty enumeration
  • enumeratePropertyNames() => empty enumeration
  • getChildren() => empty vector
  • getContent() => ""
  • getLineNr() => 0
  • getName() => null

See Also: nanoxml.XMLElement#XMLElement(java.util.Hashtable) XMLElement(Hashtable) nanoxml.XMLElement#XMLElement(boolean) nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) XMLElement(Hashtable, boolean)

XMLElement

public XMLElement(Hashtable entities)
Creates and initializes a new XML element. Calling the construction is equivalent to:

Parameters: entities The entity conversion table.

Preconditions:
  • entities != null
Postconditions:
  • countChildren() => 0
  • enumerateChildren() => empty enumeration
  • enumeratePropertyNames() => empty enumeration
  • getChildren() => empty vector
  • getContent() => ""
  • getLineNr() => 0
  • getName() => null

See Also: nanoxml.XMLElement#XMLElement() nanoxml.XMLElement#XMLElement(boolean) nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) XMLElement(Hashtable, boolean)

XMLElement

public XMLElement(boolean skipLeadingWhitespace)
Creates and initializes a new XML element. Calling the construction is equivalent to:

Parameters: skipLeadingWhitespace true if leading and trailing whitespace in PCDATA content has to be removed.

Postconditions:
  • countChildren() => 0
  • enumerateChildren() => empty enumeration
  • enumeratePropertyNames() => empty enumeration
  • getChildren() => empty vector
  • getContent() => ""
  • getLineNr() => 0
  • getName() => null

See Also: nanoxml.XMLElement#XMLElement() nanoxml.XMLElement#XMLElement(java.util.Hashtable) XMLElement(Hashtable) nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) XMLElement(Hashtable, boolean)

XMLElement

public XMLElement(Hashtable entities, boolean skipLeadingWhitespace)
Creates and initializes a new XML element. Calling the construction is equivalent to:

Parameters: entities The entity conversion table. skipLeadingWhitespace true if leading and trailing whitespace in PCDATA content has to be removed.

Preconditions:
  • entities != null
Postconditions:
  • countChildren() => 0
  • enumerateChildren() => empty enumeration
  • enumeratePropertyNames() => empty enumeration
  • getChildren() => empty vector
  • getContent() => ""
  • getLineNr() => 0
  • getName() => null

See Also: nanoxml.XMLElement#XMLElement() nanoxml.XMLElement#XMLElement(boolean) nanoxml.XMLElement#XMLElement(java.util.Hashtable) XMLElement(Hashtable)

XMLElement

public XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)
Creates and initializes a new XML element.

Parameters: entities The entity conversion table. skipLeadingWhitespace true if leading and trailing whitespace in PCDATA content has to be removed. ignoreCase true if the case of element and attribute names have to be ignored.

Preconditions:
  • entities != null
Postconditions:
  • countChildren() => 0
  • enumerateChildren() => empty enumeration
  • enumeratePropertyNames() => empty enumeration
  • getChildren() => empty vector
  • getContent() => ""
  • getLineNr() => 0
  • getName() => null

See Also: nanoxml.XMLElement#XMLElement() nanoxml.XMLElement#XMLElement(boolean) nanoxml.XMLElement#XMLElement(java.util.Hashtable) XMLElement(Hashtable) nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) XMLElement(Hashtable, boolean)

XMLElement

protected XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)
Creates and initializes a new XML element.

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

Parameters: entities The entity conversion table. skipLeadingWhitespace true if leading and trailing whitespace in PCDATA content has to be removed. fillBasicConversionTable true if the basic entities need to be added to the entity list. ignoreCase true if the case of element and attribute names have to be ignored.

Preconditions:
  • entities != null
  • if fillBasicConversionTable == false then entities contains at least the following entries: amp, lt, gt, apos and quot
Postconditions:
  • countChildren() => 0
  • enumerateChildren() => empty enumeration
  • enumeratePropertyNames() => empty enumeration
  • getChildren() => empty vector
  • getContent() => ""
  • getLineNr() => 0
  • getName() => null

See Also: nanoxml.XMLElement#createAnotherElement()

Method Detail

addChild

public void addChild(XMLElement child)
Adds a child element.

Parameters: child The child element to add.

Preconditions:
  • child != null
  • child.getName() != null
  • child does not have a parent element
Postconditions:
  • countChildren() => old.countChildren() + 1
  • enumerateChildren() => old.enumerateChildren() + child
  • getChildren() => old.enumerateChildren() + child

See Also: nanoxml.XMLElement#countChildren() nanoxml.XMLElement#enumerateChildren() nanoxml.XMLElement#getChildren() nanoxml.XMLElement#removeChild(nanoxml.XMLElement) removeChild(XMLElement)

addProperty

public void addProperty(String name, Object value)

Deprecated: Use setAttribute instead.

Adds or modifies an attribute.

Parameters: name The name of the attribute. value The value of the attribute.

addProperty

public void addProperty(String key, int value)

Deprecated: Use setIntAttribute instead.

Adds or modifies an attribute.

Parameters: name The name of the attribute. value The value of the attribute.

addProperty

public void addProperty(String name, double value)

Deprecated: Use setDoubleAttribute instead.

Adds or modifies an attribute.

Parameters: name The name of the attribute. value The value of the attribute.

checkCDATA

protected boolean checkCDATA(StringBuffer buf)
Scans a special tag and if the tag is a CDATA section, append its content to buf.
Preconditions:
  • buf != null
  • The first < has already been read.

checkLiteral

protected boolean checkLiteral(String literal)
Scans the data for literal text. Scanning stops when a character does not match or after the complete text has been checked, whichever comes first.

Parameters: literal the literal to check.

Preconditions:
  • literal != null

completeElement

protected void completeElement()

countChildren

public int countChildren()
Returns the number of child elements of the element.
Postconditions:
  • result >= 0

See Also: nanoxml.XMLElement#addChild(nanoxml.XMLElement) addChild(XMLElement) nanoxml.XMLElement#enumerateChildren() nanoxml.XMLElement#getChildren() nanoxml.XMLElement#removeChild(nanoxml.XMLElement) removeChild(XMLElement)

createAnotherElement

protected XMLElement createAnotherElement()
Creates a new similar XML element.

You should override this method when subclassing XMLElement.

enumerateAttributeNames

public Enumeration enumerateAttributeNames()
Enumerates the attribute names.
Postconditions:
  • result != null

See Also: nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#getAttribute(java.lang.String) getAttribute(String) nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) getAttribute(String, String) nanoxml.XMLElement#getAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getStringAttribute(java.lang.String) getStringAttribute(String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.lang.String) getStringAttribute(String, String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getStringAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getIntAttribute(java.lang.String) getIntAttribute(String) nanoxml.XMLElement#getIntAttribute(java.lang.String, int) getIntAttribute(String, int) nanoxml.XMLElement#getIntAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getIntAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getDoubleAttribute(java.lang.String) getDoubleAttribute(String) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) getDoubleAttribute(String, double) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getDoubleAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getBooleanAttribute(java.lang.String, java.lang.String, java.lang.String, boolean) getBooleanAttribute(String, String, String, boolean)

enumerateChildren

public Enumeration enumerateChildren()
Enumerates the child elements.
Postconditions:
  • result != null

See Also: nanoxml.XMLElement#addChild(nanoxml.XMLElement) addChild(XMLElement) nanoxml.XMLElement#countChildren() nanoxml.XMLElement#getChildren() nanoxml.XMLElement#removeChild(nanoxml.XMLElement) removeChild(XMLElement)

enumeratePropertyNames

public Enumeration enumeratePropertyNames()

Deprecated: Use enumerateAttributeNames instead.

Enumerates the attribute names.

expectedInput

protected XMLParseException expectedInput(String charSet)
Creates a parse exception for when the next character read is not the character that was expected.

Parameters: charSet The set of characters (in human readable form) that was expected.

Preconditions:
  • charSet != null
  • charSet.length() > 0

getAttribute

public Object getAttribute(String name)
Returns an attribute of the element. If the attribute doesn't exist, null is returned.

Parameters: name The name of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) getAttribute(String, Object) nanoxml.XMLElement#getAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getAttribute(String, Hashtable, String, boolean)

getAttribute

public Object getAttribute(String name, Object defaultValue)
Returns an attribute of the element. If the attribute doesn't exist, defaultValue is returned.

Parameters: name The name of the attribute. defaultValue Key to use if the attribute is missing.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getAttribute(java.lang.String) getAttribute(String) nanoxml.XMLElement#getAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getAttribute(String, Hashtable, String, boolean)

getAttribute

public Object getAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals)
Returns an attribute by looking up a key in a hashtable. If the attribute doesn't exist, the value corresponding to defaultKey is returned.

As an example, if valueSet contains the mapping "one" => "1" and the element contains the attribute attr="one", then getAttribute("attr", mapping, defaultKey, false) returns "1".

Parameters: name The name of the attribute. valueSet Hashtable mapping keys to values. defaultKey Key to use if the attribute is missing. allowLiterals true if literals are valid.

Preconditions:
  • name != null
  • name is a valid XML identifier
  • valueSet != null
  • the keys of valueSet are strings

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getAttribute(java.lang.String) getAttribute(String) nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) getAttribute(String, Object)

getBooleanAttribute

public boolean getBooleanAttribute(String name, String trueValue, String falseValue, boolean defaultValue)
Returns an attribute of the element. If the attribute doesn't exist, defaultValue is returned. If the value of the attribute is equal to trueValue, true is returned. If the value of the attribute is equal to falseValue, false is returned. If the value doesn't match trueValue or falseValue, an exception is thrown.

Parameters: name The name of the attribute. trueValue The value associated with true. falseValue The value associated with true. defaultValue Value to use if the attribute is missing.

Preconditions:
  • name != null
  • name is a valid XML identifier
  • trueValue and falseValue are different strings.

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames()

getChildren

public Vector getChildren()
Returns the child elements as a Vector. It is safe to modify this Vector.
Postconditions:
  • result != null

See Also: nanoxml.XMLElement#addChild(nanoxml.XMLElement) addChild(XMLElement) nanoxml.XMLElement#countChildren() nanoxml.XMLElement#enumerateChildren() nanoxml.XMLElement#removeChild(nanoxml.XMLElement) removeChild(XMLElement)

getContent

public String getContent()
Returns the PCDATA content of the object. If there is no such content, null is returned.

See Also: nanoxml.XMLElement#setContent(java.lang.String) setContent(String)

getContents

public String getContents()

Deprecated: Use getContent instead.

Returns the PCDATA content of the object. If there is no such content, null is returned.

getDoubleAttribute

public double getDoubleAttribute(String name)
Returns an attribute of the element. If the attribute doesn't exist, 0.0 is returned.

Parameters: name The name of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) getDoubleAttribute(String, double) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getDoubleAttribute(String, Hashtable, String, boolean)

getDoubleAttribute

public double getDoubleAttribute(String name, double defaultValue)
Returns an attribute of the element. If the attribute doesn't exist, defaultValue is returned.

Parameters: name The name of the attribute. defaultValue Key to use if the attribute is missing.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getDoubleAttribute(java.lang.String) getDoubleAttribute(String) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getDoubleAttribute(String, Hashtable, String, boolean)

getDoubleAttribute

public double getDoubleAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiteralNumbers)
Returns an attribute by looking up a key in a hashtable. If the attribute doesn't exist, the value corresponding to defaultKey is returned.

As an example, if valueSet contains the mapping "one" => 1.0 and the element contains the attribute attr="one", then getDoubleAttribute("attr", mapping, defaultKey, false) returns 1.0.

Parameters: name The name of the attribute. valueSet Hashtable mapping keys to values. defaultKey Key to use if the attribute is missing. allowLiteralNumbers true if literal numbers are valid.

Preconditions:
  • name != null
  • name is a valid XML identifier
  • valueSet != null
  • the keys of valueSet are strings
  • the values of valueSet are Double objects
  • defaultKey is either null, a key in valueSet or a double.

See Also: nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getDoubleAttribute(java.lang.String) getDoubleAttribute(String) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) getDoubleAttribute(String, double)

getIntAttribute

public int getIntAttribute(String name)
Returns an attribute of the element. If the attribute doesn't exist, 0 is returned.

Parameters: name The name of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getIntAttribute(java.lang.String, int) getIntAttribute(String, int) nanoxml.XMLElement#getIntAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getIntAttribute(String, Hashtable, String, boolean)

getIntAttribute

public int getIntAttribute(String name, int defaultValue)
Returns an attribute of the element. If the attribute doesn't exist, defaultValue is returned.

Parameters: name The name of the attribute. defaultValue Key to use if the attribute is missing.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getIntAttribute(java.lang.String) getIntAttribute(String) nanoxml.XMLElement#getIntAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getIntAttribute(String, Hashtable, String, boolean)

getIntAttribute

public int getIntAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiteralNumbers)
Returns an attribute by looking up a key in a hashtable. If the attribute doesn't exist, the value corresponding to defaultKey is returned.

As an example, if valueSet contains the mapping "one" => 1 and the element contains the attribute attr="one", then getIntAttribute("attr", mapping, defaultKey, false) returns 1.

Parameters: name The name of the attribute. valueSet Hashtable mapping keys to values. defaultKey Key to use if the attribute is missing. allowLiteralNumbers true if literal numbers are valid.

Preconditions:
  • name != null
  • name is a valid XML identifier
  • valueSet != null
  • the keys of valueSet are strings
  • the values of valueSet are Integer objects
  • defaultKey is either null, a key in valueSet or an integer.

See Also: nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getIntAttribute(java.lang.String) getIntAttribute(String) nanoxml.XMLElement#getIntAttribute(java.lang.String, int) getIntAttribute(String, int)

getIntProperty

public int getIntProperty(String name, Hashtable valueSet, String defaultKey)

Deprecated: Use getIntAttribute instead.

Returns an attribute by looking up a key in a hashtable.

getLineNr

public int getLineNr()
Returns the line nr in the source data on which the element is found. This method returns 0 there is no associated source data.
Postconditions:
  • result >= 0

getName

public String getName()
Returns the name of the element.

See Also: nanoxml.XMLElement#setName(java.lang.String) setName(String)

getProperty

public String getProperty(String name)

Deprecated: Use getStringAttribute instead.

Returns an attribute.

getProperty

public String getProperty(String name, String defaultValue)

Deprecated: Use getStringAttribute instead.

Returns an attribute.

getProperty

public int getProperty(String name, int defaultValue)

Deprecated: Use getIntAttribute instead.

Returns an attribute.

getProperty

public double getProperty(String name, double defaultValue)

Deprecated: Use getDoubleAttribute instead.

Returns an attribute.

getProperty

public boolean getProperty(String key, String trueValue, String falseValue, boolean defaultValue)

Deprecated: Use getBooleanAttribute instead.

Returns an attribute.

getProperty

public Object getProperty(String name, Hashtable valueSet, String defaultKey)

Deprecated: Use getAttribute instead.

Returns an attribute by looking up a key in a hashtable.

getSpecialDoubleProperty

public double getSpecialDoubleProperty(String name, Hashtable valueSet, String defaultKey)

Deprecated: Use getDoubleAttribute instead.

Returns an attribute by looking up a key in a hashtable.

getSpecialIntProperty

public int getSpecialIntProperty(String name, Hashtable valueSet, String defaultKey)

Deprecated: Use getIntAttribute instead.

Returns an attribute by looking up a key in a hashtable.

getStringAttribute

public String getStringAttribute(String name)
Returns an attribute of the element. If the attribute doesn't exist, null is returned.

Parameters: name The name of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getStringAttribute(java.lang.String, java.lang.String) getStringAttribute(String, String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getStringAttribute(String, Hashtable, String, boolean)

getStringAttribute

public String getStringAttribute(String name, String defaultValue)
Returns an attribute of the element. If the attribute doesn't exist, defaultValue is returned.

Parameters: name The name of the attribute. defaultValue Key to use if the attribute is missing.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getStringAttribute(java.lang.String) getStringAttribute(String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getStringAttribute(String, Hashtable, String, boolean)

getStringAttribute

public String getStringAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals)
Returns an attribute by looking up a key in a hashtable. If the attribute doesn't exist, the value corresponding to defaultKey is returned.

As an example, if valueSet contains the mapping "one" => "1" and the element contains the attribute attr="one", then getAttribute("attr", mapping, defaultKey, false) returns "1".

Parameters: name The name of the attribute. valueSet Hashtable mapping keys to values. defaultKey Key to use if the attribute is missing. allowLiterals true if literals are valid.

Preconditions:
  • name != null
  • name is a valid XML identifier
  • valueSet != null
  • the keys of valueSet are strings
  • the values of valueSet are strings

See Also: nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getStringAttribute(java.lang.String) getStringAttribute(String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.lang.String) getStringAttribute(String, String)

getStringProperty

public String getStringProperty(String name, Hashtable valueSet, String defaultKey)

Deprecated: Use getStringAttribute instead.

Returns an attribute by looking up a key in a hashtable.

getTagName

public String getTagName()

Deprecated: Use getName instead.

Returns the name of the element.

getUserObject

public Object getUserObject()

invalidValue

protected XMLParseException invalidValue(String name, String value)
Creates a parse exception for when an invalid value is given to a method.

Parameters: name The name of the entity. value The value of the entity.

Preconditions:
  • name != null
  • value != null

invalidValueSet

protected XMLParseException invalidValueSet(String name)
Creates a parse exception for when an invalid valueset is given to a method.

Parameters: name The name of the entity.

Preconditions:
  • name != null

parseCharArray

public void parseCharArray(char[] input, int offset, int end)
Reads one XML element from a char array and parses it.

Parameters: reader The reader from which to retrieve the XML data. offset The first character in string to scan. end The character where to stop scanning. This character is not scanned.

Preconditions:
  • input != null
  • end <= input.length
  • offset < end
  • offset >= 0
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader

Throws: nanoxml.XMLParseException If an error occured while parsing the string.

parseCharArray

public void parseCharArray(char[] input, int offset, int end, int startingLineNr)
Reads one XML element from a char array and parses it.

Parameters: reader The reader from which to retrieve the XML data. offset The first character in string to scan. end The character where to stop scanning. This character is not scanned. startingLineNr The line number of the first line in the data.

Preconditions:
  • input != null
  • end <= input.length
  • offset < end
  • offset >= 0
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader

Throws: nanoxml.XMLParseException If an error occured while parsing the string.

parseFromReader

public void parseFromReader(Reader reader)
Reads one XML element from a java.io.Reader and parses it.

Parameters: reader The reader from which to retrieve the XML data.

Preconditions:
  • reader != null
  • reader is not closed
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader
  • the reader points to the first character following the last '>' character of the XML element

Throws: java.io.IOException If an error occured while reading the input. nanoxml.XMLParseException If an error occured while parsing the read data.

parseFromReader

public void parseFromReader(Reader reader, int startingLineNr)
Reads one XML element from a java.io.Reader and parses it.

Parameters: reader The reader from which to retrieve the XML data. startingLineNr The line number of the first line in the data.

Preconditions:
  • reader != null
  • reader is not closed
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader
  • the reader points to the first character following the last '>' character of the XML element

Throws: java.io.IOException If an error occured while reading the input. nanoxml.XMLParseException If an error occured while parsing the read data.

parseString

public void parseString(String string)
Reads one XML element from a String and parses it.

Parameters: reader The reader from which to retrieve the XML data.

Preconditions:
  • string != null
  • string.length() > 0
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader

Throws: nanoxml.XMLParseException If an error occured while parsing the string.

parseString

public void parseString(String string, int offset)
Reads one XML element from a String and parses it.

Parameters: reader The reader from which to retrieve the XML data. offset The first character in string to scan.

Preconditions:
  • string != null
  • offset < string.length()
  • offset >= 0
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader

Throws: nanoxml.XMLParseException If an error occured while parsing the string.

parseString

public void parseString(String string, int offset, int end)
Reads one XML element from a String and parses it.

Parameters: reader The reader from which to retrieve the XML data. offset The first character in string to scan. end The character where to stop scanning. This character is not scanned.

Preconditions:
  • string != null
  • end <= string.length()
  • offset < end
  • offset >= 0
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader

Throws: nanoxml.XMLParseException If an error occured while parsing the string.

parseString

public void parseString(String string, int offset, int end, int startingLineNr)
Reads one XML element from a String and parses it.

Parameters: reader The reader from which to retrieve the XML data. offset The first character in string to scan. end The character where to stop scanning. This character is not scanned. startingLineNr The line number of the first line in the data.

Preconditions:
  • string != null
  • end <= string.length()
  • offset < end
  • offset >= 0
Postconditions:
  • the state of the receiver is updated to reflect the XML element parsed from the reader

Throws: nanoxml.XMLParseException If an error occured while parsing the string.

readChar

protected char readChar()
Reads a character from a reader.

removeAttribute

public void removeAttribute(String name)
Removes an attribute.

Parameters: name The name of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier
Postconditions:
  • enumerateAttributeNames() => old.enumerateAttributeNames() - name
  • getAttribute(name) => null

See Also: nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#getAttribute(java.lang.String) getAttribute(String) nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) getAttribute(String, Object) nanoxml.XMLElement#getAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getStringAttribute(java.lang.String) getStringAttribute(String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.lang.String) getStringAttribute(String, String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getStringAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getIntAttribute(java.lang.String) getIntAttribute(String) nanoxml.XMLElement#getIntAttribute(java.lang.String, int) getIntAttribute(String, int) nanoxml.XMLElement#getIntAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getIntAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getDoubleAttribute(java.lang.String) getDoubleAttribute(String) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) getDoubleAttribute(String, double) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getDoubleAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getBooleanAttribute(java.lang.String, java.lang.String, java.lang.String, boolean) getBooleanAttribute(String, String, String, boolean)

removeChild

public void removeChild(XMLElement child)
Removes a child element.

Parameters: child The child element to remove.

Preconditions:
  • child != null
  • child is a child element of the receiver
Postconditions:
  • countChildren() => old.countChildren() - 1
  • enumerateChildren() => old.enumerateChildren() - child
  • getChildren() => old.enumerateChildren() - child

See Also: nanoxml.XMLElement#addChild(nanoxml.XMLElement) addChild(XMLElement) nanoxml.XMLElement#countChildren() nanoxml.XMLElement#enumerateChildren() nanoxml.XMLElement#getChildren()

removeChild

public void removeChild(String name)

Deprecated: Use removeAttribute instead.

Removes an attribute.

Parameters: name The name of the attribute.

removeProperty

public void removeProperty(String name)

Deprecated: Use removeAttribute instead.

Removes an attribute.

Parameters: name The name of the attribute.

resolveEntity

protected void resolveEntity(StringBuffer buf)
Resolves an entity. The name of the entity is read from the reader. The value of the entity is appended to buf.

Parameters: buf Where to put the entity value.

Preconditions:
  • The first & has already been read.
  • buf != null

scanElement

protected void scanElement(XMLElement elt)
Scans an XML element.

Parameters: elt The element that will contain the result.

Preconditions:
  • The first < has already been read.
  • elt != null

scanIdentifier

protected void scanIdentifier(StringBuffer result)
Scans an identifier from the current reader. The scanned identifier is appended to result.

Parameters: result The buffer in which the scanned identifier will be put.

Preconditions:
  • result != null
  • The next character read from the reader is a valid first character of an XML identifier.
Postconditions:
  • The next character read from the reader won't be an identifier character.

scanPCData

protected void scanPCData(StringBuffer data)
Scans a #PCDATA element. CDATA sections and entities are resolved. The next < char is skipped. The scanned data is appended to data.
Preconditions:
  • data != null

scanString

protected void scanString(StringBuffer string)
This method scans a delimited string from the current reader. The scanned string without delimiters is appended to string.
Preconditions:
  • string != null
  • the next char read is the string delimiter

scanWhitespace

protected char scanWhitespace()
This method scans an identifier from the current reader.

Returns: the next character following the whitespace.

scanWhitespace

protected char scanWhitespace(StringBuffer result)
This method scans an identifier from the current reader. The scanned whitespace is appended to result.

Returns: the next character following the whitespace.

Preconditions:
  • result != null

setAttribute

public void setAttribute(String name, Object value)
Adds or modifies an attribute.

Parameters: name The name of the attribute. value The value of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier
  • value != null
Postconditions:
  • enumerateAttributeNames() => old.enumerateAttributeNames() + name
  • getAttribute(name) => value

See Also: nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getAttribute(java.lang.String) getAttribute(String) nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) getAttribute(String, Object) nanoxml.XMLElement#getAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getAttribute(String, Hashtable, String, boolean) nanoxml.XMLElement#getStringAttribute(java.lang.String) getStringAttribute(String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.lang.String) getStringAttribute(String, String) nanoxml.XMLElement#getStringAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getStringAttribute(String, Hashtable, String, boolean)

setContent

public void setContent(String content)
Changes the content string.

Parameters: content The new content string.

setDoubleAttribute

public void setDoubleAttribute(String name, double value)
Adds or modifies an attribute.

Parameters: name The name of the attribute. value The value of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier
Postconditions:
  • enumerateAttributeNames() => old.enumerateAttributeNames() + name
  • getDoubleAttribute(name) => value

See Also: nanoxml.XMLElement#setIntAttribute(java.lang.String, int) setIntAttribute(String, int) nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getDoubleAttribute(java.lang.String) getDoubleAttribute(String) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) getDoubleAttribute(String, double) nanoxml.XMLElement#getDoubleAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getDoubleAttribute(String, Hashtable, String, boolean)

setIntAttribute

public void setIntAttribute(String name, int value)
Adds or modifies an attribute.

Parameters: name The name of the attribute. value The value of the attribute.

Preconditions:
  • name != null
  • name is a valid XML identifier
Postconditions:
  • enumerateAttributeNames() => old.enumerateAttributeNames() + name
  • getIntAttribute(name) => value

See Also: nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) setDoubleAttribute(String, double) nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) setAttribute(String, Object) nanoxml.XMLElement#removeAttribute(java.lang.String) removeAttribute(String) nanoxml.XMLElement#enumerateAttributeNames() nanoxml.XMLElement#getIntAttribute(java.lang.String) getIntAttribute(String) nanoxml.XMLElement#getIntAttribute(java.lang.String, int) getIntAttribute(String, int) nanoxml.XMLElement#getIntAttribute(java.lang.String, java.util.Hashtable, java.lang.String, boolean) getIntAttribute(String, Hashtable, String, boolean)

setName

public void setName(String name)
Changes the name of the element.

Parameters: name The new name.

Preconditions:
  • name != null
  • name is a valid XML identifier

See Also: nanoxml.XMLElement#getName()

setTagName

public void setTagName(String name)

Deprecated: Use setName instead.

Changes the name of the element.

Parameters: name The new name.

skipComment

protected void skipComment()
Skips a comment.
Preconditions:
  • The first <!-- has already been read.

skipSpecialTag

protected void skipSpecialTag(int bracketLevel)
Skips a special tag or comment.

Parameters: bracketLevel The number of open square brackets ([) that have already been read.

Preconditions:
  • The first <! has already been read.
  • bracketLevel >= 0

syntaxError

protected XMLParseException syntaxError(String context)
Creates a parse exception for when a syntax error occured.

Parameters: context The context in which the error occured.

Preconditions:
  • context != null
  • context.length() > 0

toString

public String toString()
Writes the XML element to a string.

See Also: nanoxml.XMLElement#write(java.io.Writer) write(Writer)

unexpectedEndOfData

protected XMLParseException unexpectedEndOfData()
Creates a parse exception for when the end of the data input has been reached.

unknownEntity

protected XMLParseException unknownEntity(String name)
Creates a parse exception for when an entity could not be resolved.

Parameters: name The name of the entity.

Preconditions:
  • name != null
  • name.length() > 0

unreadChar

protected void unreadChar(char ch)
Pushes a character back to the read-back buffer.

Parameters: ch The character to push back.

Preconditions:
  • The read-back buffer is empty.
  • ch != '\0'

write

public void write(Writer writer)
Writes the XML element to a writer.

Parameters: writer The writer to write the XML data to.

Preconditions:
  • writer != null
  • writer is not closed

Throws: java.io.IOException If the data could not be written to the writer.

See Also: nanoxml.XMLElement#toString()

write

public void write(Writer writer, boolean withClosingTag)

writeClosingTag

public void writeClosingTag(Writer writer)

writeEncoded

protected void writeEncoded(Writer writer, String str)
Writes a string encoded to a writer.

Parameters: writer The writer to write the XML data to. str The string to write encoded.

Preconditions:
  • writer != null
  • writer is not closed
  • str != null

writeWithoutClosingTag

public void writeWithoutClosingTag(Writer writer)