Package net.n3.nanoxml
Class XMLElement
java.lang.Object
net.n3.nanoxml.XMLElement
- All Implemented Interfaces:
Serializable,IXMLElement
XMLElement is an XML element. The standard NanoXML builder generates a
tree of such elements.
- Version:
- $Name: RELEASE_2_2_1 $, $Revision: 1.5 $
- Author:
- Marc De Scheemaecker
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty element to be used for #PCDATA content.XMLElement(String fullName) Creates an empty element.XMLElement(String fullName, String namespace) Creates an empty element.XMLElement(String fullName, String systemID, int lineNr) Creates an empty element.XMLElement(String fullName, String namespace, String systemID, int lineNr) Creates an empty element. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChild(IXMLElement child) Adds a child element.createElement(String fullName) Creates an empty element.createElement(String fullName, String namespace) Creates an empty element.createElement(String fullName, String systemID, int lineNr) Creates an empty element.createElement(String fullName, String namespace, String systemID, int lineNr) Creates an empty element.Creates an element to be used for #PCDATA content.Returns an enumeration of all attribute names.Returns an enumeration of all child elements.booleanReturns true if the element equals another element.booleanReturns true if the element equals another element.protected voidfinalize()Cleans up the object when it's destroyed.getAttribute(String name) Deprecated.intgetAttribute(String name, int defaultValue) Returns the value of an attribute.getAttribute(String name, String defaultValue) Returns the value of an attribute.intgetAttribute(String name, String namespace, int defaultValue) Returns the value of an attribute.getAttribute(String name, String namespace, String defaultValue) Returns the value of an attribute.intReturns the number of attributes.getAttributeNamespace(String name) Returns the namespace of an attribute.Returns all attributes as a Properties object.getAttributesInNamespace(String namespace) Returns all attributes in a specific namespace as a Properties object.getAttributeType(String name) Returns the type of an attribute.getAttributeType(String name, String namespace) Returns the type of an attribute.getChildAtIndex(int index) Returns the child at a specific index.Returns a vector containing all the child elements.intReturns the number of children.getChildrenNamed(String name) Returns a vector of all child elements named name.getChildrenNamed(String name, String namespace) Returns a vector of all child elements named name.Return the #PCDATA content of the element.getFirstChildNamed(String name) Searches a child element.getFirstChildNamed(String name, String namespace) Searches a child element.Returns the full name (i.e.intReturns the line number in the data where the element started.getName()Returns the name of the element.Returns the namespace of the element.Returns the parent element.Returns the system ID of the data where the element started.booleanhasAttribute(String name) Returns whether an attribute exists.booleanhasAttribute(String name, String namespace) Returns whether an attribute exists.booleanReturns whether the element has children.voidinsertChild(IXMLElement child, int index) Inserts a child element.booleanisLeaf()Returns whether the element is a leaf element.voidremoveAttribute(String name) Removes an attribute.voidremoveAttribute(String name, String namespace) Removes an attribute.voidremoveChild(IXMLElement child) Removes a child element.voidremoveChildAtIndex(int index) Removes the child located at a certain index.voidsetAttribute(String name, String value) Sets an attribute.voidsetAttribute(String fullName, String namespace, String value) Sets an attribute.voidsetContent(String content) Sets the #PCDATA content.voidSets the full name.voidSets the name.
-
Field Details
-
NO_LINE
public static final int NO_LINENo line number defined.- See Also:
-
-
Constructor Details
-
XMLElement
public XMLElement()Creates an empty element to be used for #PCDATA content. -
XMLElement
Creates an empty element.- Parameters:
fullName- the name of the element.
-
XMLElement
Creates an empty element.- Parameters:
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.
-
XMLElement
Creates an empty element.- Parameters:
fullName- the full name of the elementnamespace- the namespace URI.
-
XMLElement
Creates an empty element.- Parameters:
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.
-
-
Method Details
-
createPCDataElement
Creates an element to be used for #PCDATA content.- Specified by:
createPCDataElementin interfaceIXMLElement
-
createElement
Creates an empty element.- Specified by:
createElementin interfaceIXMLElement- Parameters:
fullName- the name of the element.
-
createElement
Creates an empty element.- Specified by:
createElementin interfaceIXMLElement- Parameters:
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
Creates an empty element.- Specified by:
createElementin interfaceIXMLElement- Parameters:
fullName- the full name of the elementnamespace- the namespace URI.
-
createElement
Creates an empty element.- Specified by:
createElementin interfaceIXMLElement- Parameters:
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.
-
finalize
Cleans up the object when it's destroyed. -
getParent
Returns the parent element. This method returns null for the root element.- Specified by:
getParentin interfaceIXMLElement
-
getFullName
Returns the full name (i.e. the name including an eventual namespace prefix) of the element.- Specified by:
getFullNamein interfaceIXMLElement- Returns:
- the name, or null if the element only contains #PCDATA.
-
getName
Returns the name of the element.- Specified by:
getNamein interfaceIXMLElement- Returns:
- the name, or null if the element only contains #PCDATA.
-
getNamespace
Returns the namespace of the element.- Specified by:
getNamespacein interfaceIXMLElement- Returns:
- the namespace, or null if no namespace is associated with the element.
-
setName
Sets the full name. This method also sets the short name and clears the namespace URI.- Specified by:
setNamein interfaceIXMLElement- Parameters:
name- the non-null name.
-
setName
Sets the name.- Specified by:
setNamein interfaceIXMLElement- Parameters:
fullName- the non-null full name.namespace- the namespace URI, which may be null.
-
addChild
Adds a child element.- Specified by:
addChildin interfaceIXMLElement- Parameters:
child- the non-null child to add.
-
insertChild
Inserts a child element.- Parameters:
child- the non-null child to add.index- where to put the child.
-
removeChild
Removes a child element.- Specified by:
removeChildin interfaceIXMLElement- Parameters:
child- the non-null child to remove.
-
removeChildAtIndex
public void removeChildAtIndex(int index) Removes the child located at a certain index.- Specified by:
removeChildAtIndexin interfaceIXMLElement- Parameters:
index- the index of the child, where the first child has index 0.
-
enumerateChildren
Returns an enumeration of all child elements.- Specified by:
enumerateChildrenin interfaceIXMLElement- Returns:
- the non-null enumeration
-
isLeaf
public boolean isLeaf()Returns whether the element is a leaf element.- Specified by:
isLeafin interfaceIXMLElement- Returns:
- true if the element has no children.
-
hasChildren
public boolean hasChildren()Returns whether the element has children.- Specified by:
hasChildrenin interfaceIXMLElement- Returns:
- true if the element has children.
-
getChildrenCount
public int getChildrenCount()Returns the number of children.- Specified by:
getChildrenCountin interfaceIXMLElement- Returns:
- the count.
-
getChildren
Returns a vector containing all the child elements.- Specified by:
getChildrenin interfaceIXMLElement- Returns:
- the vector.
-
getChildAtIndex
Returns the child at a specific index.- Specified by:
getChildAtIndexin interfaceIXMLElement- Parameters:
index- the index of the child- Returns:
- the non-null child
- Throws:
ArrayIndexOutOfBoundsException- if the index is out of bounds.
-
getFirstChildNamed
Searches a child element.- Specified by:
getFirstChildNamedin interfaceIXMLElement- Parameters:
name- the full name of the child to search for.- Returns:
- the child element, or null if no such child was found.
-
getFirstChildNamed
Searches a child element.- Specified by:
getFirstChildNamedin interfaceIXMLElement- Parameters:
name- the name of the child to search for.namespace- the namespace, which may be null.- Returns:
- the child element, or null if no such child was found.
-
getChildrenNamed
Returns a vector of all child elements named name.- Specified by:
getChildrenNamedin interfaceIXMLElement- Parameters:
name- the full name of the children to search for.- Returns:
- the non-null vector of child elements.
-
getChildrenNamed
Returns a vector of all child elements named name.- Specified by:
getChildrenNamedin interfaceIXMLElement- Parameters:
name- the name of the children to search for.namespace- the namespace, which may be null.- Returns:
- the non-null vector of child elements.
-
getAttributeCount
public int getAttributeCount()Returns the number of attributes.- Specified by:
getAttributeCountin interfaceIXMLElement
-
getAttribute
Deprecated.As of NanoXML/Java 2.1, replaced bygetAttribute(java.lang.String,java.lang.String)Returns the value of an attribute.- Specified by:
getAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.- Returns:
- the value, or null if the attribute does not exist.
-
getAttribute
Returns the value of an attribute.- Specified by:
getAttributein interfaceIXMLElement- Parameters:
name- the non-null full name of the attribute.defaultValue- the default value of the attribute.- Returns:
- the value, or defaultValue if the attribute does not exist.
-
getAttribute
Returns the value of an attribute.- Specified by:
getAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.namespace- the namespace URI, which may be null.defaultValue- the default value of the attribute.- Returns:
- the value, or defaultValue if the attribute does not exist.
-
getAttribute
Returns the value of an attribute.- Specified by:
getAttributein interfaceIXMLElement- Parameters:
name- the non-null full name of the attribute.defaultValue- the default value of the attribute.- Returns:
- the value, or defaultValue if the attribute does not exist.
-
getAttribute
Returns the value of an attribute.- Specified by:
getAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.namespace- the namespace URI, which may be null.defaultValue- the default value of the attribute.- Returns:
- the value, or defaultValue if the attribute does not exist.
-
getAttributeType
Returns the type of an attribute.- Specified by:
getAttributeTypein interfaceIXMLElement- Parameters:
name- the non-null full name of the attribute.- Returns:
- the type, or null if the attribute does not exist.
-
getAttributeNamespace
Returns the namespace of an attribute.- Specified by:
getAttributeNamespacein interfaceIXMLElement- Parameters:
name- the non-null full name of the attribute.- Returns:
- the namespace, or null if there is none associated.
-
getAttributeType
Returns the type of an attribute.- Specified by:
getAttributeTypein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.namespace- the namespace URI, which may be null.- Returns:
- the type, or null if the attribute does not exist.
-
setAttribute
Sets an attribute.- Specified by:
setAttributein interfaceIXMLElement- Parameters:
name- the non-null full name of the attribute.value- the non-null value of the attribute.
-
setAttribute
Sets an attribute.- Specified by:
setAttributein interfaceIXMLElement- Parameters:
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.
-
removeAttribute
Removes an attribute.- Specified by:
removeAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.
-
removeAttribute
Removes an attribute.- Specified by:
removeAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.namespace- the namespace URI of the attribute, which may be null.
-
enumerateAttributeNames
Returns an enumeration of all attribute names.- Specified by:
enumerateAttributeNamesin interfaceIXMLElement- Returns:
- the non-null enumeration.
-
hasAttribute
Returns whether an attribute exists.- Specified by:
hasAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.- Returns:
- true if the attribute exists.
-
hasAttribute
Returns whether an attribute exists.- Specified by:
hasAttributein interfaceIXMLElement- Parameters:
name- the non-null name of the attribute.namespace- the namespace URI of the attribute, which may be null.- Returns:
- true if the attribute exists.
-
getAttributes
Returns all attributes as a Properties object.- Specified by:
getAttributesin interfaceIXMLElement- Returns:
- the non-null set.
-
getAttributesInNamespace
Returns all attributes in a specific namespace as a Properties object.- Specified by:
getAttributesInNamespacein interfaceIXMLElement- Parameters:
namespace- the namespace URI of the attributes, which may be null.- Returns:
- the non-null set.
-
getSystemID
Returns the system ID of the data where the element started.- Specified by:
getSystemIDin interfaceIXMLElement- Returns:
- the system ID, or null if unknown.
- See Also:
-
getLineNr
public int getLineNr()Returns the line number in the data where the element started.- Specified by:
getLineNrin interfaceIXMLElement- Returns:
- the line number, or NO_LINE if unknown.
- See Also:
-
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.- Specified by:
getContentin interfaceIXMLElement- Returns:
- the content.
-
setContent
Sets the #PCDATA content. It is an error to call this method with a non-null value if there are child objects.- Specified by:
setContentin interfaceIXMLElement- Parameters:
content- the (possibly null) content.
-
equals
Returns true if the element equals another element.- Specified by:
equalsin interfaceIXMLElement- Overrides:
equalsin classObject- Parameters:
rawElement- the element to compare to
-
equalsXMLElement
Returns true if the element equals another element.- Specified by:
equalsXMLElementin interfaceIXMLElement- Parameters:
rawElement- the element to compare to
-
getAttribute(java.lang.String,java.lang.String)Returns the value of an attribute.