Class XMLElement
- 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 methodgetStringAttribute. 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 usingcountChildren.
- Elements Containing Character Data
-
If an elements contains character data, like in the following example:
<title>The Title</title>getContent.
- Subclassing XMLElement
-
When subclassing XMLElement, you need to override the method
createAnotherElementwhich has to return a new copy of the receiver.
- Version:
- $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
- Author:
- Marc De Scheemaecker <cyberelf@mac.com>
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMajor version of NanoXML.static final intMinor version of NanoXML. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates and initializes a new XML element.XMLElement(boolean skipLeadingWhitespace) Creates and initializes a new XML element.XMLElement(Hashtable entities) 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.protectedXMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase) Creates and initializes a new XML element. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(XMLElement child) Adds a child element.voidaddProperty(String name, double value) Deprecated.voidaddProperty(String key, int value) Deprecated.UsesetIntAttributeinstead.voidaddProperty(String name, Object value) Deprecated.UsesetAttributeinstead.protected booleancheckCDATA(StringBuffer buf) Scans a special tag and if the tag is a CDATA section, append its content tobuf.protected booleancheckLiteral(String literal) Scans the data for literal text.intReturns the number of child elements of the element.protected XMLElementCreates a new similar XML element.Enumerates the attribute names.Enumerates the child elements.Deprecated.UseenumerateAttributeNamesinstead.protected XMLParseExceptionexpectedInput(String charSet) Creates a parse exception for when the next character read is not the character that was expected.getAttribute(String name) Returns an attribute of the element.getAttribute(String name, Object defaultValue) Returns an attribute of the element.getAttribute(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.Returns the child elements as a Vector.Returns the PCDATA content of the object.Deprecated.UsegetContentinstead.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) Deprecated.UsegetIntAttributeinstead.intReturns the line nr in the source data on which the element is found.getName()Returns the name of the element.getProperty(String name) Deprecated.UsegetStringAttributeinstead.doublegetProperty(String name, double defaultValue) Deprecated.UsegetDoubleAttributeinstead.intgetProperty(String name, int defaultValue) Deprecated.UsegetIntAttributeinstead.getProperty(String name, String defaultValue) Deprecated.UsegetStringAttributeinstead.booleangetProperty(String key, String trueValue, String falseValue, boolean defaultValue) Deprecated.UsegetBooleanAttributeinstead.getProperty(String name, Hashtable valueSet, String defaultKey) Deprecated.UsegetAttributeinstead.doublegetSpecialDoubleProperty(String name, Hashtable valueSet, String defaultKey) Deprecated.UsegetDoubleAttributeinstead.intgetSpecialIntProperty(String name, Hashtable valueSet, String defaultKey) Deprecated.UsegetIntAttributeinstead.getStringAttribute(String name) Returns an attribute of the element.getStringAttribute(String name, String defaultValue) Returns an attribute of the element.getStringAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals) Returns an attribute by looking up a key in a hashtable.getStringProperty(String name, Hashtable valueSet, String defaultKey) Deprecated.UsegetStringAttributeinstead.Deprecated.UsegetNameinstead.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(String name) Deprecated.UseremoveAttributeinstead.voidremoveChild(XMLElement child) Removes a child element.voidremoveProperty(String name) Deprecated.UseremoveAttributeinstead.protected voidResolves 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 charThis 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.voidChanges the name of the element.voidsetTagName(String name) Deprecated.UsesetNameinstead.protected voidSkips 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.toString()Writes the XML element to a string.protected XMLParseExceptionCreates 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.voidWrites the XML element to a writer.protected voidwriteEncoded(Writer writer, String str) Writes a string encoded to a writer.
-
Field Details
-
NANOXML_MAJOR_VERSION
public static final int NANOXML_MAJOR_VERSIONMajor 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_MINOR_VERSION
public static final int NANOXML_MINOR_VERSIONMinor 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:
-
-
Constructor Details
-
XMLElement
public XMLElement()Creates and initializes a new XML element. Calling the construction is equivalent to:new XMLElement(new Hashtable(), false, true)- Postconditions:
-
- countChildren() => 0
- enumerateChildren() => empty enumeration
- enumeratePropertyNames() => empty enumeration
- getChildren() => empty vector
- getContent() => ""
- getLineNr() => 0
- getName() => null
- See Also:
-
XMLElement
Creates and initializes a new XML element. Calling the construction is equivalent to:new XMLElement(entities, false, true)- 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:
-
XMLElement
public XMLElement(boolean skipLeadingWhitespace) Creates and initializes a new XML element. Calling the construction is equivalent to:new XMLElement(new Hashtable(), skipLeadingWhitespace, true)- Parameters:
skipLeadingWhitespace-trueif 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:
-
XMLElement
Creates and initializes a new XML element. Calling the construction is equivalent to:new XMLElement(entities, skipLeadingWhitespace, true)- Parameters:
entities- The entity conversion table.skipLeadingWhitespace-trueif 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:
-
XMLElement
Creates and initializes a new XML element.- Parameters:
entities- The entity conversion table.skipLeadingWhitespace-trueif leading and trailing whitespace in PCDATA content has to be removed.ignoreCase-trueif 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:
-
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
createAnotherElementto create child elements.- Parameters:
entities- The entity conversion table.skipLeadingWhitespace-trueif leading and trailing whitespace in PCDATA content has to be removed.fillBasicConversionTable-trueif the basic entities need to be added to the entity list.ignoreCase-trueif the case of element and attribute names have to be ignored.
- Preconditions:
-
entities != null- if
fillBasicConversionTable == falsethenentitiescontains at least the following entries:amp,lt,gt,aposandquot
- Postconditions:
-
- countChildren() => 0
- enumerateChildren() => empty enumeration
- enumeratePropertyNames() => empty enumeration
- getChildren() => empty vector
- getContent() => ""
- getLineNr() => 0
- getName() => null
- See Also:
-
-
Method Details
-
addChild
Adds a child element.- Parameters:
child- The child element to add.
- Preconditions:
-
child != nullchild.getName() != nullchilddoes not have a parent element
- Postconditions:
-
- countChildren() => old.countChildren() + 1
- enumerateChildren() => old.enumerateChildren() + child
- getChildren() => old.enumerateChildren() + child
- See Also:
-
setAttribute
Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifiervalue != null
- Postconditions:
-
- enumerateAttributeNames() => old.enumerateAttributeNames() + name
- getAttribute(name) => value
- See Also:
-
addProperty
Deprecated.UsesetAttributeinstead.Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
-
setIntAttribute
Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- Postconditions:
-
- enumerateAttributeNames() => old.enumerateAttributeNames() + name
- getIntAttribute(name) => value
- See Also:
-
addProperty
Deprecated.UsesetIntAttributeinstead.Adds or modifies an attribute.- Parameters:
value- The value of the attribute.name- The name of the attribute.
-
setDoubleAttribute
Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- Postconditions:
-
- enumerateAttributeNames() => old.enumerateAttributeNames() + name
- getDoubleAttribute(name) => value
- See Also:
-
addProperty
Deprecated.UsesetDoubleAttributeinstead.Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
-
countChildren
public int countChildren()Returns the number of child elements of the element.- Postconditions:
-
result >= 0
- See Also:
-
enumerateAttributeNames
Enumerates the attribute names.- Postconditions:
-
result != null
- See Also:
-
enumeratePropertyNames
Deprecated.UseenumerateAttributeNamesinstead.Enumerates the attribute names. -
enumerateChildren
Enumerates the child elements.- Postconditions:
-
result != null
- See Also:
-
getChildren
Returns the child elements as a Vector. It is safe to modify this Vector.- Postconditions:
-
result != null
- See Also:
-
getContents
Deprecated.UsegetContentinstead.Returns the PCDATA content of the object. If there is no such content,nullis returned. -
getContent
Returns the PCDATA content of the object. If there is no such content,nullis returned.- See Also:
-
getLineNr
public int getLineNr()Returns the line nr in the source data on which the element is found. This method returns0there is no associated source data.- Postconditions:
-
result >= 0
-
getAttribute
Returns an attribute of the element. If the attribute doesn't exist,nullis returned.- Parameters:
name- The name of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
getAttribute
Returns an attribute of the element. If the attribute doesn't exist,defaultValueis returned.- Parameters:
name- The name of the attribute.defaultValue- Key to use if the attribute is missing.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
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 attributeattr="one", thengetAttribute("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-trueif literals are valid.
- Preconditions:
-
name != nullnameis a valid XML identifiervalueSet!= null- the keys of
valueSetare strings
- See Also:
-
getStringAttribute
Returns an attribute of the element. If the attribute doesn't exist,nullis returned.- Parameters:
name- The name of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
getStringAttribute
Returns an attribute of the element. If the attribute doesn't exist,defaultValueis returned.- Parameters:
name- The name of the attribute.defaultValue- Key to use if the attribute is missing.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
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 attributeattr="one", thengetAttribute("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-trueif literals are valid.
- Preconditions:
-
name != nullnameis a valid XML identifiervalueSet!= null- the keys of
valueSetare strings - the values of
valueSetare strings
- See Also:
-
getIntAttribute
Returns an attribute of the element. If the attribute doesn't exist,0is returned.- Parameters:
name- The name of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
getIntAttribute
Returns an attribute of the element. If the attribute doesn't exist,defaultValueis returned.- Parameters:
name- The name of the attribute.defaultValue- Key to use if the attribute is missing.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
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" => 1and the element contains the attributeattr="one", thengetIntAttribute("attr", mapping, defaultKey, false)returns1.- Parameters:
name- The name of the attribute.valueSet- Hashtable mapping keys to values.defaultKey- Key to use if the attribute is missing.allowLiteralNumbers-trueif literal numbers are valid.
- Preconditions:
-
name != nullnameis a valid XML identifiervalueSet!= null- the keys of
valueSetare strings - the values of
valueSetare Integer objects defaultKeyis eithernull, a key invalueSetor an integer.
- See Also:
-
getDoubleAttribute
Returns an attribute of the element. If the attribute doesn't exist,0.0is returned.- Parameters:
name- The name of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
getDoubleAttribute
Returns an attribute of the element. If the attribute doesn't exist,defaultValueis returned.- Parameters:
name- The name of the attribute.defaultValue- Key to use if the attribute is missing.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
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.0and the element contains the attributeattr="one", thengetDoubleAttribute("attr", mapping, defaultKey, false)returns1.0.- Parameters:
name- The name of the attribute.valueSet- Hashtable mapping keys to values.defaultKey- Key to use if the attribute is missing.allowLiteralNumbers-trueif literal numbers are valid.
- Preconditions:
-
name != nullnameis a valid XML identifiervalueSet != null- the keys of
valueSetare strings - the values of
valueSetare Double objects defaultKeyis eithernull, a key invalueSetor a double.
- See Also:
-
getBooleanAttribute
public boolean getBooleanAttribute(String name, String trueValue, String falseValue, boolean defaultValue) Returns an attribute of the element. If the attribute doesn't exist,defaultValueis returned. If the value of the attribute is equal totrueValue,trueis returned. If the value of the attribute is equal tofalseValue,falseis returned. If the value doesn't matchtrueValueorfalseValue, an exception is thrown.- Parameters:
name- The name of the attribute.trueValue- The value associated withtrue.falseValue- The value associated withtrue.defaultValue- Value to use if the attribute is missing.
- Preconditions:
-
name != nullnameis a valid XML identifiertrueValueandfalseValueare different strings.
- See Also:
-
getIntProperty
Deprecated.UsegetIntAttributeinstead.Returns an attribute by looking up a key in a hashtable. -
getProperty
Deprecated.UsegetStringAttributeinstead.Returns an attribute. -
getProperty
Deprecated.UsegetStringAttributeinstead.Returns an attribute. -
getProperty
Deprecated.UsegetIntAttributeinstead.Returns an attribute. -
getProperty
Deprecated.UsegetDoubleAttributeinstead.Returns an attribute. -
getProperty
Deprecated.UsegetBooleanAttributeinstead.Returns an attribute. -
getProperty
Deprecated.UsegetAttributeinstead.Returns an attribute by looking up a key in a hashtable. -
getStringProperty
Deprecated.UsegetStringAttributeinstead.Returns an attribute by looking up a key in a hashtable. -
getSpecialIntProperty
Deprecated.UsegetIntAttributeinstead.Returns an attribute by looking up a key in a hashtable. -
getSpecialDoubleProperty
Deprecated.UsegetDoubleAttributeinstead.Returns an attribute by looking up a key in a hashtable. -
getName
Returns the name of the element.- See Also:
-
getTagName
Deprecated.UsegetNameinstead.Returns the name of the element. -
parseFromReader
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 != nullreaderis 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:
IOException- If an error occured while reading the input.XMLParseException- If an error occured while parsing the read data.
-
parseFromReader
public void parseFromReader(Reader reader, int startingLineNr) throws IOException, XMLParseException 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 != nullreaderis 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:
IOException- If an error occured while reading the input.XMLParseException- If an error occured while parsing the read data.
-
parseString
Reads one XML element from a String and parses it.- Parameters:
reader- The reader from which to retrieve the XML data.
- Preconditions:
-
string != nullstring.length() > 0
- Postconditions:
-
- the state of the receiver is updated to reflect the XML element parsed from the reader
- Throws:
XMLParseException- If an error occured while parsing the string.
-
parseString
Reads one XML element from a String and parses it.- Parameters:
offset- The first character instringto scan.
- Preconditions:
-
string != nulloffset < string.length()offset >= 0
- Postconditions:
-
- the state of the receiver is updated to reflect the XML element parsed from the reader
reader- The reader from which to retrieve the XML data.- Throws:
XMLParseException- If an error occured while parsing the string.
-
parseString
Reads one XML element from a String and parses it.- Parameters:
offset- The first character instringto scan.end- The character where to stop scanning. This character is not scanned.
- Preconditions:
-
string != nullend <= string.length()offset < endoffset >= 0
- Postconditions:
-
- the state of the receiver is updated to reflect the XML element parsed from the reader
reader- The reader from which to retrieve the XML data.- Throws:
XMLParseException- If an error occured while parsing the string.
-
parseString
public void parseString(String string, int offset, int end, int startingLineNr) throws XMLParseException Reads one XML element from a String and parses it.- Parameters:
offset- The first character instringto 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 != nullend <= string.length()offset < endoffset >= 0
- Postconditions:
-
- the state of the receiver is updated to reflect the XML element parsed from the reader
reader- The reader from which to retrieve the XML data.- Throws:
XMLParseException- If an error occured while parsing the string.
-
parseCharArray
Reads one XML element from a char array and parses it.- Parameters:
offset- The first character instringto scan.end- The character where to stop scanning. This character is not scanned.
- Preconditions:
-
input != nullend <= input.lengthoffset < endoffset >= 0
- Postconditions:
-
- the state of the receiver is updated to reflect the XML element parsed from the reader
reader- The reader from which to retrieve the XML data.- Throws:
XMLParseException- If an error occured while parsing the string.
-
parseCharArray
public void parseCharArray(char[] input, int offset, int end, int startingLineNr) throws XMLParseException Reads one XML element from a char array and parses it.- Parameters:
offset- The first character instringto 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 != nullend <= input.lengthoffset < endoffset >= 0
- Postconditions:
-
- the state of the receiver is updated to reflect the XML element parsed from the reader
reader- The reader from which to retrieve the XML data.- Throws:
XMLParseException- If an error occured while parsing the string.
-
removeChild
Removes a child element.- Parameters:
child- The child element to remove.
- Preconditions:
-
child != nullchildis a child element of the receiver
- Postconditions:
-
- countChildren() => old.countChildren() - 1
- enumerateChildren() => old.enumerateChildren() - child
- getChildren() => old.enumerateChildren() - child
- See Also:
-
removeAttribute
Removes an attribute.- Parameters:
name- The name of the attribute.
- Preconditions:
-
name != nullnameis a valid XML identifier
- Postconditions:
-
- enumerateAttributeNames() => old.enumerateAttributeNames() - name
- getAttribute(name) =>
null
- See Also:
-
removeProperty
Deprecated.UseremoveAttributeinstead.Removes an attribute.- Parameters:
name- The name of the attribute.
-
removeChild
Deprecated.UseremoveAttributeinstead.Removes an attribute.- Parameters:
name- The name of the attribute.
-
createAnotherElement
Creates a new similar XML element.You should override this method when subclassing XMLElement.
-
setContent
Changes the content string.- Parameters:
content- The new content string.
-
setTagName
Deprecated.UsesetNameinstead.Changes the name of the element.- Parameters:
name- The new name.
-
setName
Changes the name of the element.- Parameters:
name- The new name.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
-
toString
Writes the XML element to a string. -
write
Writes the XML element to a writer.- Parameters:
writer- The writer to write the XML data to.
- Preconditions:
-
writer != nullwriteris not closed
- Throws:
IOException- If the data could not be written to the writer.- See Also:
-
writeEncoded
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 != nullwriteris not closedstr != null
- Throws:
IOException -
scanIdentifier
Scans an identifier from the current reader. The scanned identifier is appended toresult.- 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.
- Throws:
IOException
-
scanWhitespace
This method scans an identifier from the current reader.- Returns:
- the next character following the whitespace.
- Throws:
IOException
-
scanWhitespace
This method scans an identifier from the current reader. The scanned whitespace is appended toresult.- Returns:
- the next character following the whitespace.
- Preconditions:
-
result != null
- Throws:
IOException -
scanString
This method scans a delimited string from the current reader. The scanned string without delimiters is appended tostring.- Preconditions:
-
string != null- the next char read is the string delimiter
- Throws:
IOException
-
scanPCData
Scans a #PCDATA element. CDATA sections and entities are resolved. The next < char is skipped. The scanned data is appended todata.- Preconditions:
-
data != null
- Throws:
IOException
-
checkCDATA
Scans a special tag and if the tag is a CDATA section, append its content tobuf.- Preconditions:
-
buf != null- The first < has already been read.
- Throws:
IOException
-
skipComment
Skips a comment.- Preconditions:
-
- The first <!-- has already been read.
- Throws:
IOException
-
skipSpecialTag
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
- Throws:
IOException -
checkLiteral
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
- Throws:
IOException -
readChar
Reads a character from a reader.- Throws:
IOException
-
scanElement
Scans an XML element.- Parameters:
elt- The element that will contain the result.
- Preconditions:
-
- The first < has already been read.
elt != null
- Throws:
IOException -
resolveEntity
Resolves an entity. The name of the entity is read from the reader. The value of the entity is appended tobuf.- Parameters:
buf- Where to put the entity value.
- Preconditions:
-
- The first & has already been read.
buf != null
- Throws:
IOException -
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'
-
invalidValueSet
Creates a parse exception for when an invalid valueset is given to a method.- Parameters:
name- The name of the entity.
- Preconditions:
-
name != null
-
invalidValue
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 != nullvalue != null
-
unexpectedEndOfData
Creates a parse exception for when the end of the data input has been reached. -
syntaxError
Creates a parse exception for when a syntax error occured.- Parameters:
context- The context in which the error occured.
- Preconditions:
-
context != nullcontext.length() > 0
-
expectedInput
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 != nullcharSet.length() > 0
-
unknownEntity
Creates a parse exception for when an entity could not be resolved.- Parameters:
name- The name of the entity.
- Preconditions:
-
name != nullname.length() > 0
-
setDoubleAttributeinstead.