Package net.n3.nanoxml
Interface IXMLElement
-
- All Known Implementing Classes:
XMLElement
public interface IXMLElementIXMLElement is an XML element. It provides an easy to use generic interface on top of an XML like data structure like e.g. a DOM like structure. Elements returned by StdXMLBuilder also implement this interface.- Version:
- $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
- Author:
- Marc De Scheemaecker
- See Also:
StdXMLBuilder
-
-
Field Summary
Fields Modifier and Type Field Description static intNO_LINENo line number defined.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidaddChild(IXMLElement child)Adds a child element.IXMLElementcreateElement(String fullName)Creates an empty element.IXMLElementcreateElement(String fullName, String namespace)Creates an empty element.IXMLElementcreateElement(String fullName, String systemID, int lineNr)Creates an empty element.IXMLElementcreateElement(String fullName, String namespace, String systemID, int lineNr)Creates an empty element.IXMLElementcreatePCDataElement()Creates an element to be used for #PCDATA content.EnumerationenumerateAttributeNames()Returns an enumeration of all attribute names.EnumerationenumerateChildren()Returns an enumeration of all child elements.booleanequals(Object rawElement)Returns true if the element equals another element.booleanequalsXMLElement(IXMLElement elt)Returns true if the element equals another element.StringgetAttribute(String name)Deprecated.As of NanoXML/Java 2.0.1, replaced bygetAttribute(java.lang.String,java.lang.String)Returns the value of an attribute.intgetAttribute(String name, int defaultValue)Returns the value of an attribute.StringgetAttribute(String name, String defaultValue)Returns the value of an attribute.intgetAttribute(String name, String namespace, int defaultValue)Returns the value of an attribute.StringgetAttribute(String name, String namespace, String defaultValue)Returns the value of an attribute.intgetAttributeCount()Returns the number of attributes.StringgetAttributeNamespace(String name)Returns the namespace of an attribute.PropertiesgetAttributes()Returns all attributes as a Properties object.PropertiesgetAttributesInNamespace(String namespace)Returns all attributes in a specific namespace as a Properties object.StringgetAttributeType(String name)Returns the type of an attribute.StringgetAttributeType(String name, String namespace)Returns the type of an attribute.IXMLElementgetChildAtIndex(int index)Returns the child at a specific index.VectorgetChildren()Returns a vector containing all the child elements.intgetChildrenCount()Returns the number of children.VectorgetChildrenNamed(String name)Returns a vector of all child elements named name.VectorgetChildrenNamed(String name, String namespace)Returns a vector of all child elements named name.StringgetContent()Return the #PCDATA content of the element.IXMLElementgetFirstChildNamed(String name)Searches a child element.IXMLElementgetFirstChildNamed(String name, String namespace)Searches a child element.StringgetFullName()Returns the full name (i.e.intgetLineNr()Returns the line number in the data where the element started.StringgetName()Returns the name of the element.StringgetNamespace()Returns the namespace of the element.IXMLElementgetParent()Returns the parent element.StringgetSystemID()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.booleanhasChildren()Returns whether the element has children.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.voidsetName(String name)Sets the full name.voidsetName(String fullName, String namespace)Sets the name.
-
-
-
Field Detail
-
NO_LINE
static final int NO_LINE
No line number defined.- See Also:
- Constant Field Values
-
-
Method Detail
-
createPCDataElement
IXMLElement createPCDataElement()
Creates an element to be used for #PCDATA content.
-
createElement
IXMLElement createElement(String fullName)
Creates an empty element.- Parameters:
fullName- the name of the element.
-
createElement
IXMLElement createElement(String fullName, String systemID, int lineNr)
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.
-
createElement
IXMLElement createElement(String fullName, String namespace)
Creates an empty element.- Parameters:
fullName- the full name of the elementnamespace- the namespace URI.
-
createElement
IXMLElement createElement(String fullName, String namespace, String systemID, int lineNr)
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.
-
getParent
IXMLElement getParent()
Returns the parent element. This method returns null for the root element.
-
getFullName
String getFullName()
Returns the full name (i.e. the name including an eventual namespace prefix) of the element.- Returns:
- the name, or null if the element only contains #PCDATA.
-
getName
String getName()
Returns the name of the element.- Returns:
- the name, or null if the element only contains #PCDATA.
-
getNamespace
String getNamespace()
Returns the namespace of the element.- Returns:
- the namespace, or null if no namespace is associated with the element.
-
setName
void setName(String name)
Sets the full name. This method also sets the short name and clears the namespace URI.- Parameters:
name- the non-null name.
-
setName
void setName(String fullName, String namespace)
Sets the name.- Parameters:
fullName- the non-null full name.namespace- the namespace URI, which may be null.
-
addChild
void addChild(IXMLElement child)
Adds a child element.- Parameters:
child- the non-null child to add.
-
removeChild
void removeChild(IXMLElement child)
Removes a child element.- Parameters:
child- the non-null child to remove.
-
removeChildAtIndex
void removeChildAtIndex(int index)
Removes the child located at a certain index.- Parameters:
index- the index of the child, where the first child has index 0.
-
enumerateChildren
Enumeration enumerateChildren()
Returns an enumeration of all child elements.- Returns:
- the non-null enumeration
-
isLeaf
boolean isLeaf()
Returns whether the element is a leaf element.- Returns:
- true if the element has no children.
-
hasChildren
boolean hasChildren()
Returns whether the element has children.- Returns:
- true if the element has children.
-
getChildrenCount
int getChildrenCount()
Returns the number of children.- Returns:
- the count.
-
getChildren
Vector getChildren()
Returns a vector containing all the child elements.- Returns:
- the vector.
-
getChildAtIndex
IXMLElement getChildAtIndex(int index) throws ArrayIndexOutOfBoundsException
Returns the child at a specific index.- Parameters:
index- the index of the child- Returns:
- the non-null child
- Throws:
ArrayIndexOutOfBoundsException- if the index is out of bounds.
-
getFirstChildNamed
IXMLElement getFirstChildNamed(String name)
Searches a child element.- Parameters:
name- the full name of the child to search for.- Returns:
- the child element, or null if no such child was found.
-
getFirstChildNamed
IXMLElement getFirstChildNamed(String name, String namespace)
Searches a child element.- 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
Vector getChildrenNamed(String name)
Returns a vector of all child elements named name.- Parameters:
name- the full name of the children to search for.- Returns:
- the non-null vector of child elements.
-
getChildrenNamed
Vector getChildrenNamed(String name, String namespace)
Returns a vector of all child elements named name.- 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
int getAttributeCount()
Returns the number of attributes.
-
getAttribute
String getAttribute(String name)
Deprecated.As of NanoXML/Java 2.0.1, replaced bygetAttribute(java.lang.String,java.lang.String)Returns the value of an attribute.- Parameters:
name- the non-null name of the attribute.- Returns:
- the value, or null if the attribute does not exist.
-
getAttribute
String getAttribute(String name, String defaultValue)
Returns the value of an attribute.- 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
String getAttribute(String name, String namespace, String defaultValue)
Returns the value of an attribute.- 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
int getAttribute(String name, int defaultValue)
Returns the value of an attribute.- 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
int getAttribute(String name, String namespace, int defaultValue)
Returns the value of an attribute.- 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
String getAttributeType(String name)
Returns the type of an attribute.- Parameters:
name- the non-null full name of the attribute.- Returns:
- the type, or null if the attribute does not exist.
-
getAttributeNamespace
String getAttributeNamespace(String name)
Returns the namespace of an attribute.- Parameters:
name- the non-null full name of the attribute.- Returns:
- the namespace, or null if there is none associated.
-
getAttributeType
String getAttributeType(String name, String namespace)
Returns the type of an attribute.- 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
void setAttribute(String name, String value)
Sets an attribute.- Parameters:
name- the non-null full name of the attribute.value- the non-null value of the attribute.
-
setAttribute
void setAttribute(String fullName, String namespace, String value)
Sets an attribute.- 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
void removeAttribute(String name)
Removes an attribute.- Parameters:
name- the non-null name of the attribute.
-
removeAttribute
void removeAttribute(String name, String namespace)
Removes an attribute.- Parameters:
name- the non-null name of the attribute.namespace- the namespace URI of the attribute, which may be null.
-
enumerateAttributeNames
Enumeration enumerateAttributeNames()
Returns an enumeration of all attribute names.- Returns:
- the non-null enumeration.
-
hasAttribute
boolean hasAttribute(String name)
Returns whether an attribute exists.- Parameters:
name- the non-null name of the attribute.- Returns:
- true if the attribute exists.
-
hasAttribute
boolean hasAttribute(String name, String namespace)
Returns whether an attribute exists.- 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
Properties getAttributes()
Returns all attributes as a Properties object.- Returns:
- the non-null set.
-
getAttributesInNamespace
Properties getAttributesInNamespace(String namespace)
Returns all attributes in a specific namespace as a Properties object.- Parameters:
namespace- the namespace URI of the attributes, which may be null.- Returns:
- the non-null set.
-
getSystemID
String getSystemID()
Returns the system ID of the data where the element started.- Returns:
- the system ID, or null if unknown.
- See Also:
getLineNr()
-
getLineNr
int getLineNr()
Returns the line number in the data where the element started.- Returns:
- the line number, or NO_LINE if unknown.
- See Also:
NO_LINE,getSystemID()
-
getContent
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.- Returns:
- the content.
-
setContent
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.- Parameters:
content- the (possibly null) content.
-
equals
boolean equals(Object rawElement)
Returns true if the element equals another element.
-
equalsXMLElement
boolean equalsXMLElement(IXMLElement elt)
Returns true if the element equals another element.- Parameters:
rawElement- the element to compare to
-
-