JHotDraw 7.5.1

net.n3.nanoxml
Interface IXMLElement

All Known Implementing Classes:
XMLElement

public interface IXMLElement

IXMLElement 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
static int NO_LINE
          No line number defined.
 
Method Summary
 void addChild(IXMLElement child)
          Adds a child element.
 IXMLElement createElement(java.lang.String fullName)
          Creates an empty element.
 IXMLElement createElement(java.lang.String fullName, java.lang.String namespace)
          Creates an empty element.
 IXMLElement createElement(java.lang.String fullName, java.lang.String systemID, int lineNr)
          Creates an empty element.
 IXMLElement createElement(java.lang.String fullName, java.lang.String namespace, java.lang.String systemID, int lineNr)
          Creates an empty element.
 IXMLElement createPCDataElement()
          Creates an element to be used for #PCDATA content.
 void dispose()
          Gets rid of the IXMLElement and of all its children.
 boolean equals(java.lang.Object rawElement)
          Returns true if the element equals another element.
 boolean equalsXMLElement(IXMLElement elt)
          Returns true if the element equals another element.
 java.lang.String getAttribute(java.lang.String name)
          Deprecated. As of NanoXML/Java 2.0.1, replaced by getAttribute(java.lang.String,java.lang.String) Returns the value of an attribute.
 int getAttribute(java.lang.String name, int defaultValue)
          Returns the value of an attribute.
 java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
          Returns the value of an attribute.
 int getAttribute(java.lang.String name, java.lang.String namespace, int defaultValue)
          Returns the value of an attribute.
 java.lang.Object getAttribute(java.lang.String name, java.lang.String namespace, java.util.Map valueSet, java.lang.String defaultKey)
          Returns an attribute by looking up a key in a hashtable.
 java.lang.String getAttribute(java.lang.String name, java.lang.String namespace, java.lang.String defaultValue)
          Returns the value of an attribute.
 int getAttributeCount()
          Returns the number of attributes.
 java.lang.String getAttributeNamespace(java.lang.String name)
          Returns the namespace of an attribute.
 java.util.Properties getAttributes()
          Returns all attributes as a Properties object.
 java.util.Properties getAttributesInNamespace(java.lang.String namespace)
          Returns all attributes in a specific namespace as a Properties object.
 java.lang.String getAttributeType(java.lang.String name)
          Returns the type of an attribute.
 java.lang.String getAttributeType(java.lang.String name, java.lang.String namespace)
          Returns the type of an attribute.
 IXMLElement getChildAtIndex(int index)
          Returns the child at a specific index.
 java.util.ArrayList<IXMLElement> getChildren()
          Returns a vector containing all the child elements.
 int getChildrenCount()
          Returns the number of children.
 java.util.ArrayList<IXMLElement> getChildrenNamed(java.lang.String name)
          Returns a vector of all child elements named name.
 java.util.ArrayList<IXMLElement> getChildrenNamed(java.lang.String name, java.lang.String namespace)
          Returns a vector of all child elements named name.
 java.lang.String getContent()
          Return the #PCDATA content of the element.
 double getDoubleAttribute(java.lang.String name, java.lang.String namespace, double defaultValue)
          Returns an attribute of the element.
 IXMLElement getFirstChildNamed(java.lang.String name)
          Searches a child element.
 IXMLElement getFirstChildNamed(java.lang.String name, java.lang.String namespace)
          Searches a child element.
 java.lang.String getFullName()
          Returns the full name (i.e.
 int getLineNr()
          Returns the line number in the data where the element started.
 java.lang.String getName()
          Returns the name of the element.
 java.lang.String getNamespace()
          Returns the namespace of the element.
 IXMLElement getParent()
          Returns the parent element.
 java.lang.String getSystemID()
          Returns the system ID of the data where the element started.
 boolean hasAttribute(java.lang.String name)
          Returns whether an attribute exists.
 boolean hasAttribute(java.lang.String name, java.lang.String namespace)
          Returns whether an attribute exists.
 boolean hasChildren()
          Returns whether the element has children.
 boolean isLeaf()
          Returns whether the element is a leaf element.
 java.util.Iterator<java.lang.String> iterateAttributeNames()
          Returns an enumeration of all attribute names.
 java.util.Iterator<IXMLElement> iterateChildren()
          Returns an enumeration of all child elements.
 void removeAttribute(java.lang.String name)
          Removes an attribute.
 void removeAttribute(java.lang.String name, java.lang.String namespace)
          Removes an attribute.
 void removeChild(IXMLElement child)
          Removes a child element.
 void removeChildAtIndex(int index)
          Removes the child located at a certain index.
 void setAttribute(java.lang.String name, java.lang.String value)
          Sets an attribute.
 void setAttribute(java.lang.String fullName, java.lang.String namespace, java.lang.String value)
          Sets an attribute.
 void setContent(java.lang.String content)
          Sets the #PCDATA content.
 void setName(java.lang.String name)
          Sets the full name.
 void setName(java.lang.String fullName, java.lang.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(java.lang.String fullName)
Creates an empty element.

Parameters:
fullName - the name of the element.

createElement

IXMLElement createElement(java.lang.String fullName,
                          java.lang.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(java.lang.String fullName,
                          java.lang.String namespace)
Creates an empty element.

Parameters:
fullName - the full name of the element
namespace - the namespace URI.

createElement

IXMLElement createElement(java.lang.String fullName,
                          java.lang.String namespace,
                          java.lang.String systemID,
                          int lineNr)
Creates an empty element.

Parameters:
fullName - the full name of the element
namespace - 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

java.lang.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

java.lang.String getName()
Returns the name of the element.

Returns:
the name, or null if the element only contains #PCDATA.

getNamespace

java.lang.String getNamespace()
Returns the namespace of the element.

Returns:
the namespace, or null if no namespace is associated with the element.

setName

void setName(java.lang.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(java.lang.String fullName,
             java.lang.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.

iterateChildren

java.util.Iterator<IXMLElement> iterateChildren()
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

java.util.ArrayList<IXMLElement> getChildren()
Returns a vector containing all the child elements.

Returns:
the vector.

getChildAtIndex

IXMLElement getChildAtIndex(int index)
                            throws java.lang.ArrayIndexOutOfBoundsException
Returns the child at a specific index.

Parameters:
index - the index of the child
Returns:
the non-null child
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is out of bounds.

getFirstChildNamed

IXMLElement getFirstChildNamed(java.lang.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(java.lang.String name,
                               java.lang.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

java.util.ArrayList<IXMLElement> getChildrenNamed(java.lang.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

java.util.ArrayList<IXMLElement> getChildrenNamed(java.lang.String name,
                                                  java.lang.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

java.lang.String getAttribute(java.lang.String name)
Deprecated. As of NanoXML/Java 2.0.1, replaced by getAttribute(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

java.lang.String getAttribute(java.lang.String name,
                              java.lang.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

java.lang.String getAttribute(java.lang.String name,
                              java.lang.String namespace,
                              java.lang.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(java.lang.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(java.lang.String name,
                 java.lang.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.

getAttribute

java.lang.Object getAttribute(java.lang.String name,
                              java.lang.String namespace,
                              java.util.Map valueSet,
                              java.lang.String defaultKey)
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 attribute attr="one", then getAttribute("attr", mapping, defaultKey, false) returns "1".

Parameters:
name - The name of the attribute.
namespace - the namespace URI, which may be null.
valueSet - HashMap mapping keySet().iterator to values.
defaultKey - Key to use if the attribute is missing.
Preconditions:
  • name != null
  • name is a valid XML identifier
  • valueSet != null
  • the keySet().iterator of valueSet are strings

getDoubleAttribute

double getDoubleAttribute(java.lang.String name,
                          java.lang.String namespace,
                          double defaultValue)
Returns an attribute of the element. If the attribute doesn't exist, defaultValue is returned.

Parameters:
name - The name of the attribute.
namespace - the namespace URI, which may be null.
defaultValue - Key to use if the attribute is missing.

getAttributeType

java.lang.String getAttributeType(java.lang.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

java.lang.String getAttributeNamespace(java.lang.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

java.lang.String getAttributeType(java.lang.String name,
                                  java.lang.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(java.lang.String name,
                  java.lang.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(java.lang.String fullName,
                  java.lang.String namespace,
                  java.lang.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(java.lang.String name)
Removes an attribute.

Parameters:
name - the non-null name of the attribute.

removeAttribute

void removeAttribute(java.lang.String name,
                     java.lang.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.

iterateAttributeNames

java.util.Iterator<java.lang.String> iterateAttributeNames()
Returns an enumeration of all attribute names.

Returns:
the non-null enumeration.

hasAttribute

boolean hasAttribute(java.lang.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(java.lang.String name,
                     java.lang.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

java.util.Properties getAttributes()
Returns all attributes as a Properties object.

Returns:
the non-null set.

getAttributesInNamespace

java.util.Properties getAttributesInNamespace(java.lang.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

java.lang.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

java.lang.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(java.lang.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(java.lang.Object rawElement)
Returns true if the element equals another element.

Overrides:
equals in class java.lang.Object
Parameters:
rawElement - the element to compare to

equalsXMLElement

boolean equalsXMLElement(IXMLElement elt)
Returns true if the element equals another element.

Parameters:
elt - the element to compare to

dispose

void dispose()
Gets rid of the IXMLElement and of all its children.


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.