Package org.jvnet.lafplugin
Class XMLElement
- java.lang.Object
-
- org.jvnet.lafplugin.XMLElement
-
public class XMLElement extends java.lang.ObjectXMLElement 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 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.
- See Also:
nanoxml.XMLParseException
-
-
Field Summary
Fields Modifier and Type Field Description static intNANOXML_MAJOR_VERSIONMajor version of NanoXML.static intNANOXML_MINOR_VERSIONMinor version of NanoXML.
-
Constructor Summary
Constructors Constructor Description XMLElement()Creates and initializes a new XML element.XMLElement(boolean skipLeadingWhitespace)Creates and initializes a new XML element.XMLElement(java.util.Hashtable entities)Creates and initializes a new XML element.XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace)Creates and initializes a new XML element.XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)Creates and initializes a new XML element.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChild(XMLElement child)Adds a child element.voidaddProperty(java.lang.String name, double value)Deprecated.UsesetDoubleAttributeinstead.voidaddProperty(java.lang.String key, int value)Deprecated.UsesetIntAttributeinstead.voidaddProperty(java.lang.String name, java.lang.Object value)Deprecated.UsesetAttributeinstead.intcountChildren()Returns the number of child elements of the element.java.util.EnumerationenumerateAttributeNames()Enumerates the attribute names.java.util.EnumerationenumerateChildren()Enumerates the child elements.java.util.EnumerationenumeratePropertyNames()Deprecated.UseenumerateAttributeNamesinstead.java.lang.ObjectgetAttribute(java.lang.String name)Returns an attribute of the element.java.lang.ObjectgetAttribute(java.lang.String name, java.lang.Object defaultValue)Returns an attribute of the element.java.lang.ObjectgetAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey, boolean allowLiterals)Returns an attribute by looking up a key in a hashtable.booleangetBooleanAttribute(java.lang.String name, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)Returns an attribute of the element.java.util.VectorgetChildren()Returns the child elements as a Vector.java.lang.StringgetContent()Returns the PCDATA content of the object.java.lang.StringgetContents()Deprecated.UsegetContentinstead.doublegetDoubleAttribute(java.lang.String name)Returns an attribute of the element.doublegetDoubleAttribute(java.lang.String name, double defaultValue)Returns an attribute of the element.doublegetDoubleAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey, boolean allowLiteralNumbers)Returns an attribute by looking up a key in a hashtable.intgetIntAttribute(java.lang.String name)Returns an attribute of the element.intgetIntAttribute(java.lang.String name, int defaultValue)Returns an attribute of the element.intgetIntAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey, boolean allowLiteralNumbers)Returns an attribute by looking up a key in a hashtable.intgetIntProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetIntAttributeinstead.intgetLineNr()Returns the line nr in the source data on which the element is found.java.lang.StringgetName()Returns the name of the element.java.lang.StringgetProperty(java.lang.String name)Deprecated.UsegetStringAttributeinstead.doublegetProperty(java.lang.String name, double defaultValue)Deprecated.UsegetDoubleAttributeinstead.intgetProperty(java.lang.String name, int defaultValue)Deprecated.UsegetIntAttributeinstead.java.lang.StringgetProperty(java.lang.String name, java.lang.String defaultValue)Deprecated.UsegetStringAttributeinstead.booleangetProperty(java.lang.String key, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)Deprecated.UsegetBooleanAttributeinstead.java.lang.ObjectgetProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetAttributeinstead.doublegetSpecialDoubleProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetDoubleAttributeinstead.intgetSpecialIntProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetIntAttributeinstead.java.lang.StringgetStringAttribute(java.lang.String name)Returns an attribute of the element.java.lang.StringgetStringAttribute(java.lang.String name, java.lang.String defaultValue)Returns an attribute of the element.java.lang.StringgetStringAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey, boolean allowLiterals)Returns an attribute by looking up a key in a hashtable.java.lang.StringgetStringProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetStringAttributeinstead.java.lang.StringgetTagName()Deprecated.UsegetNameinstead.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(java.io.Reader reader)Reads one XML element from a java.io.Reader and parses it.voidparseFromReader(java.io.Reader reader, int startingLineNr)Reads one XML element from a java.io.Reader and parses it.voidparseString(java.lang.String string)Reads one XML element from a String and parses it.voidparseString(java.lang.String string, int offset)Reads one XML element from a String and parses it.voidparseString(java.lang.String string, int offset, int end)Reads one XML element from a String and parses it.voidparseString(java.lang.String string, int offset, int end, int startingLineNr)Reads one XML element from a String and parses it.voidremoveAttribute(java.lang.String name)Removes an attribute.voidremoveChild(java.lang.String name)Deprecated.UseremoveAttributeinstead.voidremoveChild(XMLElement child)Removes a child element.voidremoveProperty(java.lang.String name)Deprecated.UseremoveAttributeinstead.voidsetAttribute(java.lang.String name, java.lang.Object value)Adds or modifies an attribute.voidsetContent(java.lang.String content)Changes the content string.voidsetDoubleAttribute(java.lang.String name, double value)Adds or modifies an attribute.voidsetIntAttribute(java.lang.String name, int value)Adds or modifies an attribute.voidsetName(java.lang.String name)Changes the name of the element.voidsetTagName(java.lang.String name)Deprecated.UsesetNameinstead.java.lang.StringtoString()Writes the XML element to a string.voidwrite(java.io.Writer writer)Writes the XML element to a writer.
-
-
-
Field Detail
-
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, Constant Field Values
-
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, Constant Field Values
-
-
Constructor Detail
-
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(Hashtable),nanoxml.XMLElement#XMLElement(boolean),XMLElement(Hashtable, boolean)
-
XMLElement
public XMLElement(java.util.Hashtable entities)
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:
nanoxml.XMLElement#XMLElement(),nanoxml.XMLElement#XMLElement(boolean),XMLElement(Hashtable, boolean)
-
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:
nanoxml.XMLElement#XMLElement(),XMLElement(Hashtable),XMLElement(Hashtable, boolean)
-
XMLElement
public XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace)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:
nanoxml.XMLElement#XMLElement(),nanoxml.XMLElement#XMLElement(boolean),XMLElement(Hashtable)
-
XMLElement
public XMLElement(java.util.Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)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:
nanoxml.XMLElement#XMLElement(),nanoxml.XMLElement#XMLElement(boolean),XMLElement(Hashtable),XMLElement(Hashtable, boolean)
-
-
Method Detail
-
addChild
public void addChild(XMLElement child)
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:
nanoxml.XMLElement#countChildren(),nanoxml.XMLElement#enumerateChildren(),nanoxml.XMLElement#getChildren(),removeChild(XMLElement)
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)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:
setDoubleAttribute(String, double),setIntAttribute(String, int),nanoxml.XMLElement#enumerateAttributeNames(),getAttribute(String),getAttribute(String, Object),getAttribute(String, Hashtable, String, boolean),getStringAttribute(String),getStringAttribute(String, String),getStringAttribute(String, Hashtable, String, boolean)
-
addProperty
public void addProperty(java.lang.String name, java.lang.Object value)Deprecated.UsesetAttributeinstead.Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
-
setIntAttribute
public void setIntAttribute(java.lang.String name, int value)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:
setDoubleAttribute(String, double),setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getIntAttribute(String),getIntAttribute(String, int),getIntAttribute(String, Hashtable, String, boolean)
-
addProperty
public void addProperty(java.lang.String key, int value)Deprecated.UsesetIntAttributeinstead.Adds or modifies an attribute.- Parameters:
name- The name of the attribute.value- The value of the attribute.
-
setDoubleAttribute
public void setDoubleAttribute(java.lang.String name, double value)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:
setIntAttribute(String, int),setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getDoubleAttribute(String),getDoubleAttribute(String, double),getDoubleAttribute(String, Hashtable, String, boolean)
-
addProperty
public void addProperty(java.lang.String name, double value)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:
addChild(XMLElement),nanoxml.XMLElement#enumerateChildren(),nanoxml.XMLElement#getChildren(),removeChild(XMLElement)
-
enumerateAttributeNames
public java.util.Enumeration enumerateAttributeNames()
Enumerates the attribute names.- Postconditions:
-
result != null
- See Also:
setDoubleAttribute(String, double),setIntAttribute(String, int),setAttribute(String, Object),removeAttribute(String),getAttribute(String),getAttribute(String, String),getAttribute(String, Hashtable, String, boolean),getStringAttribute(String),getStringAttribute(String, String),getStringAttribute(String, Hashtable, String, boolean),getIntAttribute(String),getIntAttribute(String, int),getIntAttribute(String, Hashtable, String, boolean),getDoubleAttribute(String),getDoubleAttribute(String, double),getDoubleAttribute(String, Hashtable, String, boolean),getBooleanAttribute(String, String, String, boolean)
-
enumeratePropertyNames
public java.util.Enumeration enumeratePropertyNames()
Deprecated.UseenumerateAttributeNamesinstead.Enumerates the attribute names.
-
enumerateChildren
public java.util.Enumeration enumerateChildren()
Enumerates the child elements.- Postconditions:
-
result != null
- See Also:
addChild(XMLElement),nanoxml.XMLElement#countChildren(),nanoxml.XMLElement#getChildren(),removeChild(XMLElement)
-
getChildren
public java.util.Vector getChildren()
Returns the child elements as a Vector. It is safe to modify this Vector.- Postconditions:
-
result != null
- See Also:
addChild(XMLElement),nanoxml.XMLElement#countChildren(),nanoxml.XMLElement#enumerateChildren(),removeChild(XMLElement)
-
getContents
public java.lang.String getContents()
Deprecated.UsegetContentinstead.Returns the PCDATA content of the object. If there is no such content,nullis returned.
-
getContent
public java.lang.String getContent()
Returns the PCDATA content of the object. If there is no such content,nullis returned.- See Also:
setContent(String)
-
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
public java.lang.Object getAttribute(java.lang.String name)
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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getAttribute(String, Object),getAttribute(String, Hashtable, String, boolean)
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name, java.lang.Object defaultValue)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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getAttribute(String),getAttribute(String, Hashtable, String, boolean)
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getAttribute(String),getAttribute(String, Object)
-
getStringAttribute
public java.lang.String getStringAttribute(java.lang.String name)
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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getStringAttribute(String, String),getStringAttribute(String, Hashtable, String, boolean)
-
getStringAttribute
public java.lang.String getStringAttribute(java.lang.String name, java.lang.String defaultValue)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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getStringAttribute(String),getStringAttribute(String, Hashtable, String, boolean)
-
getStringAttribute
public java.lang.String getStringAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames(),getStringAttribute(String),getStringAttribute(String, String)
-
getIntAttribute
public int getIntAttribute(java.lang.String name)
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:
setIntAttribute(String, int),nanoxml.XMLElement#enumerateAttributeNames(),getIntAttribute(String, int),getIntAttribute(String, Hashtable, String, boolean)
-
getIntAttribute
public int getIntAttribute(java.lang.String name, int defaultValue)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:
setIntAttribute(String, int),nanoxml.XMLElement#enumerateAttributeNames(),getIntAttribute(String),getIntAttribute(String, Hashtable, String, boolean)
-
getIntAttribute
public int getIntAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.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:
setIntAttribute(String, int),nanoxml.XMLElement#enumerateAttributeNames(),getIntAttribute(String),getIntAttribute(String, int)
-
getDoubleAttribute
public double getDoubleAttribute(java.lang.String name)
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:
setDoubleAttribute(String, double),nanoxml.XMLElement#enumerateAttributeNames(),getDoubleAttribute(String, double),getDoubleAttribute(String, Hashtable, String, boolean)
-
getDoubleAttribute
public double getDoubleAttribute(java.lang.String name, double defaultValue)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:
setDoubleAttribute(String, double),nanoxml.XMLElement#enumerateAttributeNames(),getDoubleAttribute(String),getDoubleAttribute(String, Hashtable, String, boolean)
-
getDoubleAttribute
public double getDoubleAttribute(java.lang.String name, java.util.Hashtable valueSet, java.lang.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:
setDoubleAttribute(String, double),nanoxml.XMLElement#enumerateAttributeNames(),getDoubleAttribute(String),getDoubleAttribute(String, double)
-
getBooleanAttribute
public boolean getBooleanAttribute(java.lang.String name, java.lang.String trueValue, java.lang.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:
setAttribute(String, Object),removeAttribute(String),nanoxml.XMLElement#enumerateAttributeNames()
-
getIntProperty
public int getIntProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetIntAttributeinstead.Returns an attribute by looking up a key in a hashtable.
-
getProperty
public java.lang.String getProperty(java.lang.String name)
Deprecated.UsegetStringAttributeinstead.Returns an attribute.
-
getProperty
public java.lang.String getProperty(java.lang.String name, java.lang.String defaultValue)Deprecated.UsegetStringAttributeinstead.Returns an attribute.
-
getProperty
public int getProperty(java.lang.String name, int defaultValue)Deprecated.UsegetIntAttributeinstead.Returns an attribute.
-
getProperty
public double getProperty(java.lang.String name, double defaultValue)Deprecated.UsegetDoubleAttributeinstead.Returns an attribute.
-
getProperty
public boolean getProperty(java.lang.String key, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)Deprecated.UsegetBooleanAttributeinstead.Returns an attribute.
-
getProperty
public java.lang.Object getProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetAttributeinstead.Returns an attribute by looking up a key in a hashtable.
-
getStringProperty
public java.lang.String getStringProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetStringAttributeinstead.Returns an attribute by looking up a key in a hashtable.
-
getSpecialIntProperty
public int getSpecialIntProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetIntAttributeinstead.Returns an attribute by looking up a key in a hashtable.
-
getSpecialDoubleProperty
public double getSpecialDoubleProperty(java.lang.String name, java.util.Hashtable valueSet, java.lang.String defaultKey)Deprecated.UsegetDoubleAttributeinstead.Returns an attribute by looking up a key in a hashtable.
-
getName
public java.lang.String getName()
Returns the name of the element.- See Also:
setName(String)
-
getTagName
public java.lang.String getTagName()
Deprecated.UsegetNameinstead.Returns the name of the element.
-
parseFromReader
public void parseFromReader(java.io.Reader reader) throws java.io.IOException, XMLParseExceptionReads 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:
java.io.IOException- If an error occured while reading the input.nanoxml.XMLParseException- If an error occured while parsing the read data.XMLParseException
-
parseFromReader
public void parseFromReader(java.io.Reader reader, int startingLineNr) throws java.io.IOException, XMLParseExceptionReads 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:
java.io.IOException- If an error occured while reading the input.nanoxml.XMLParseException- If an error occured while parsing the read data.XMLParseException
-
parseString
public void parseString(java.lang.String string) throws XMLParseExceptionReads 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:
nanoxml.XMLParseException- If an error occured while parsing the string.XMLParseException
-
parseString
public void parseString(java.lang.String string, int offset) throws XMLParseExceptionReads one XML element from a String and parses it.- Parameters:
reader- The reader from which to retrieve the XML data.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
- Throws:
nanoxml.XMLParseException- If an error occured while parsing the string.XMLParseException
-
parseString
public void parseString(java.lang.String string, int offset, int end) throws XMLParseExceptionReads one XML element from a String and parses it.- Parameters:
reader- The reader from which to retrieve the XML data.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
- Throws:
nanoxml.XMLParseException- If an error occured while parsing the string.XMLParseException
-
parseString
public void parseString(java.lang.String string, int offset, int end, int startingLineNr) throws XMLParseExceptionReads one XML element from a String and parses it.- Parameters:
reader- The reader from which to retrieve the XML data.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
- Throws:
nanoxml.XMLParseException- If an error occured while parsing the string.XMLParseException
-
parseCharArray
public void parseCharArray(char[] input, int offset, int end) throws XMLParseExceptionReads 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 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
- Throws:
nanoxml.XMLParseException- If an error occured while parsing the string.XMLParseException
-
parseCharArray
public void parseCharArray(char[] input, int offset, int end, int startingLineNr) throws XMLParseExceptionReads 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 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
- Throws:
nanoxml.XMLParseException- If an error occured while parsing the string.XMLParseException
-
removeChild
public void removeChild(XMLElement child)
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:
addChild(XMLElement),nanoxml.XMLElement#countChildren(),nanoxml.XMLElement#enumerateChildren(),nanoxml.XMLElement#getChildren()
-
removeAttribute
public void removeAttribute(java.lang.String name)
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:
nanoxml.XMLElement#enumerateAttributeNames(),setDoubleAttribute(String, double),setIntAttribute(String, int),setAttribute(String, Object),getAttribute(String),getAttribute(String, Object),getAttribute(String, Hashtable, String, boolean),getStringAttribute(String),getStringAttribute(String, String),getStringAttribute(String, Hashtable, String, boolean),getIntAttribute(String),getIntAttribute(String, int),getIntAttribute(String, Hashtable, String, boolean),getDoubleAttribute(String),getDoubleAttribute(String, double),getDoubleAttribute(String, Hashtable, String, boolean),getBooleanAttribute(String, String, String, boolean)
-
removeProperty
public void removeProperty(java.lang.String name)
Deprecated.UseremoveAttributeinstead.Removes an attribute.- Parameters:
name- The name of the attribute.
-
removeChild
public void removeChild(java.lang.String name)
Deprecated.UseremoveAttributeinstead.Removes an attribute.- Parameters:
name- The name of the 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.UsesetNameinstead.Changes the name of the element.- Parameters:
name- The new name.
-
setName
public void setName(java.lang.String name)
Changes the name of the element.- Parameters:
name- The new name.
- Preconditions:
-
name != nullnameis a valid XML identifier
- See Also:
nanoxml.XMLElement#getName()
-
toString
public java.lang.String toString()
Writes the XML element to a string.- Overrides:
toStringin classjava.lang.Object- See Also:
write(Writer)
-
write
public void write(java.io.Writer writer) throws java.io.IOExceptionWrites the XML element to a writer.- Parameters:
writer- The writer to write the XML data to.
- Preconditions:
-
writer != nullwriteris not closed
- Throws:
java.io.IOException- If the data could not be written to the writer.- See Also:
nanoxml.XMLElement#toString()
-
-