XMLElement is an XML element. The standard NanoXML builder generates a
tree of such elements.
XMLElement
public XMLElement()
Creates an empty element to be used for #PCDATA content.
XMLElement
public XMLElement(String fullName)
Creates an empty element.
fullName
- the name of the element.
XMLElement
public XMLElement(String fullName,
String namespace)
Creates an empty element.
fullName
- the full name of the elementnamespace
- the namespace URI.
XMLElement
public XMLElement(String fullName,
String namespace,
String systemID,
int lineNr)
Creates an empty element.
fullName
- the full name of the elementnamespace
- the namespace URI.systemID
- the system ID of the XML data where the element starts.lineNr
- the line in the XML data where the element starts.
XMLElement
public XMLElement(String fullName,
String systemID,
int lineNr)
Creates an empty element.
fullName
- the name of the element.systemID
- the system ID of the XML data where the element starts.lineNr
- the line in the XML data where the element starts.
createElement
public IXMLElement createElement(String fullName,
String namespace)
Creates an empty element.
- createElement in interface IXMLElement
fullName
- the full name of the elementnamespace
- the namespace URI.
createElement
public IXMLElement createElement(String fullName,
String namespace,
String systemID,
int lineNr)
Creates an empty element.
- createElement in interface IXMLElement
fullName
- the full name of the elementnamespace
- the namespace URI.systemID
- the system ID of the XML data where the element starts.lineNr
- the line in the XML data where the element starts.
createElement
public IXMLElement createElement(String fullName,
String systemID,
int lineNr)
Creates an empty element.
- createElement in interface IXMLElement
fullName
- the name of the element.systemID
- the system ID of the XML data where the element starts.lineNr
- the line in the XML data where the element starts.
enumerateAttributeNames
public Enumeration enumerateAttributeNames()
Returns an enumeration of all attribute names.
- enumerateAttributeNames in interface IXMLElement
- the non-null enumeration.
enumerateChildren
public Enumeration enumerateChildren()
Returns an enumeration of all child elements.
- enumerateChildren in interface IXMLElement
- the non-null enumeration
equals
public boolean equals(Object rawElement)
Returns true if the element equals another element.
- equals in interface IXMLElement
rawElement
- the element to compare to
finalize
protected void finalize()
throws Throwable
Cleans up the object when it's destroyed.
getAttribute
public String getAttribute(String name)
As of NanoXML/Java 2.1, replaced by
getAttribute(java.lang.String,java.lang.String)
Returns the value of an attribute.
- getAttribute in interface IXMLElement
name
- the non-null name of the attribute.
- the value, or null if the attribute does not exist.
getAttribute
public String getAttribute(String name,
String defaultValue)
Returns the value of an attribute.
- getAttribute in interface IXMLElement
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.
- the value, or defaultValue if the attribute does not exist.
getAttribute
public String getAttribute(String name,
String namespace,
String defaultValue)
Returns the value of an attribute.
- getAttribute in interface IXMLElement
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.defaultValue
- the default value of the attribute.
- the value, or defaultValue if the attribute does not exist.
getAttribute
public int getAttribute(String name,
String namespace,
int defaultValue)
Returns the value of an attribute.
- getAttribute in interface IXMLElement
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.defaultValue
- the default value of the attribute.
- the value, or defaultValue if the attribute does not exist.
getAttribute
public int getAttribute(String name,
int defaultValue)
Returns the value of an attribute.
- getAttribute in interface IXMLElement
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.
- the value, or defaultValue if the attribute does not exist.
getAttributeNamespace
public String getAttributeNamespace(String name)
Returns the namespace of an attribute.
- getAttributeNamespace in interface IXMLElement
name
- the non-null full name of the attribute.
- the namespace, or null if there is none associated.
getAttributeType
public String getAttributeType(String name)
Returns the type of an attribute.
- getAttributeType in interface IXMLElement
name
- the non-null full name of the attribute.
- the type, or null if the attribute does not exist.
getAttributeType
public String getAttributeType(String name,
String namespace)
Returns the type of an attribute.
- getAttributeType in interface IXMLElement
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.
- the type, or null if the attribute does not exist.
getAttributes
public Properties getAttributes()
Returns all attributes as a Properties object.
- getAttributes in interface IXMLElement
- the non-null set.
getAttributesInNamespace
public Properties getAttributesInNamespace(String namespace)
Returns all attributes in a specific namespace as a Properties object.
- getAttributesInNamespace in interface IXMLElement
namespace
- the namespace URI of the attributes, which may be null.
- the non-null set.
getChildAtIndex
public IXMLElement getChildAtIndex(int index)
throws ArrayIndexOutOfBoundsException
Returns the child at a specific index.
- getChildAtIndex in interface IXMLElement
index
- the index of the child
- the non-null child
getChildren
public Vector getChildren()
Returns a vector containing all the child elements.
- getChildren in interface IXMLElement
- the vector.
getChildrenNamed
public Vector getChildrenNamed(String name)
Returns a vector of all child elements named name.
- getChildrenNamed in interface IXMLElement
name
- the full name of the children to search for.
- the non-null vector of child elements.
getChildrenNamed
public Vector getChildrenNamed(String name,
String namespace)
Returns a vector of all child elements named name.
- getChildrenNamed in interface IXMLElement
name
- the name of the children to search for.namespace
- the namespace, which may be null.
- the non-null vector of child elements.
getContent
public String getContent()
Return the #PCDATA content of the element. If the element has a
combination of #PCDATA content and child elements, the #PCDATA
sections can be retrieved as unnamed child objects. In this case,
this method returns null.
- getContent in interface IXMLElement
- the content.
getFirstChildNamed
public IXMLElement getFirstChildNamed(String name)
Searches a child element.
- getFirstChildNamed in interface IXMLElement
name
- the full name of the child to search for.
- the child element, or null if no such child was found.
getFirstChildNamed
public IXMLElement getFirstChildNamed(String name,
String namespace)
Searches a child element.
- getFirstChildNamed in interface IXMLElement
name
- the name of the child to search for.namespace
- the namespace, which may be null.
- the child element, or null if no such child was found.
getFullName
public String getFullName()
Returns the full name (i.e. the name including an eventual namespace
prefix) of the element.
- getFullName in interface IXMLElement
- the name, or null if the element only contains #PCDATA.
getName
public String getName()
Returns the name of the element.
- getName in interface IXMLElement
- the name, or null if the element only contains #PCDATA.
getNamespace
public String getNamespace()
Returns the namespace of the element.
- getNamespace in interface IXMLElement
- the namespace, or null if no namespace is associated with the
element.
getSystemID
public String getSystemID()
Returns the system ID of the data where the element started.
- getSystemID in interface IXMLElement
- the system ID, or null if unknown.
getLineNr()
hasAttribute
public boolean hasAttribute(String name)
Returns whether an attribute exists.
- hasAttribute in interface IXMLElement
- true if the attribute exists.
hasAttribute
public boolean hasAttribute(String name,
String namespace)
Returns whether an attribute exists.
- hasAttribute in interface IXMLElement
- true if the attribute exists.
hasChildren
public boolean hasChildren()
Returns whether the element has children.
- hasChildren in interface IXMLElement
- true if the element has children.
insertChild
public void insertChild(IXMLElement child,
int index)
Inserts a child element.
child
- the non-null child to add.index
- where to put the child.
isLeaf
public boolean isLeaf()
Returns whether the element is a leaf element.
- isLeaf in interface IXMLElement
- true if the element has no children.
removeAttribute
public void removeAttribute(String name)
Removes an attribute.
- removeAttribute in interface IXMLElement
name
- the non-null name of the attribute.
removeAttribute
public void removeAttribute(String name,
String namespace)
Removes an attribute.
- removeAttribute in interface IXMLElement
name
- the non-null name of the attribute.namespace
- the namespace URI of the attribute, which may be null.
removeChildAtIndex
public void removeChildAtIndex(int index)
Removes the child located at a certain index.
- removeChildAtIndex in interface IXMLElement
index
- the index of the child, where the first child has index 0.
setAttribute
public void setAttribute(String name,
String value)
Sets an attribute.
- setAttribute in interface IXMLElement
name
- the non-null full name of the attribute.value
- the non-null value of the attribute.
setAttribute
public void setAttribute(String fullName,
String namespace,
String value)
Sets an attribute.
- setAttribute in interface IXMLElement
fullName
- the non-null full name of the attribute.namespace
- the namespace URI of the attribute, which may be null.value
- the non-null value of the attribute.
setContent
public void setContent(String content)
Sets the #PCDATA content. It is an error to call this method with a
non-null value if there are child objects.
- setContent in interface IXMLElement
content
- the (possibly null) content.
setName
public void setName(String name)
Sets the full name. This method also sets the short name and clears the
namespace URI.
- setName in interface IXMLElement
name
- the non-null name.
setName
public void setName(String fullName,
String namespace)
Sets the name.
- setName in interface IXMLElement
fullName
- the non-null full name.namespace
- the namespace URI, which may be null.