|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object processing.xml.XMLElement
public class XMLElement
XMLElement is an XML element. This is the base class used for the Processing XML library, representing a single node of an XML tree. This code is based on a modified version of NanoXML by Marc De Scheemaecker.
Field Summary | |
---|---|
static int |
NO_LINE
No line number defined. |
Constructor Summary | |
---|---|
XMLElement()
Creates an empty element to be used for #PCDATA content. |
|
XMLElement(PApplet parent,
java.lang.String filename)
Begin parsing XML data passed in from a PApplet. |
|
XMLElement(java.io.Reader r)
|
|
XMLElement(java.lang.String xml)
|
|
XMLElement(java.lang.String fullName,
java.lang.String namespace,
java.lang.String systemID,
int lineNr)
Creates an empty element. |
Method Summary | |
---|---|
void |
addChild(XMLElement child)
Adds a child element. |
XMLElement |
createElement(java.lang.String fullName,
java.lang.String namespace)
Creates an empty element. |
XMLElement |
createElement(java.lang.String fullName,
java.lang.String namespace,
java.lang.String systemID,
int lineNr)
Creates an empty element. |
XMLElement |
createPCDataElement()
Creates an element to be used for #PCDATA content. |
java.util.Enumeration<java.lang.String> |
enumerateAttributeNames()
Returns an enumeration of all attribute names. |
java.util.Enumeration<XMLElement> |
enumerateChildren()
Returns an enumeration of all child elements. |
boolean |
equals(java.lang.Object rawElement)
Returns true if the element equals another element. |
boolean |
equalsXMLElement(XMLElement rawElement)
Returns true if the element equals another element. |
java.lang.String |
getAttribute(java.lang.String name)
Returns the value of an attribute. |
java.lang.String |
getAttribute(java.lang.String name,
java.lang.String defaultValue)
Returns the value of an attribute. |
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. |
XMLElement |
getChild(int which)
Quick accessor for an element at a particular index. |
XMLElement |
getChild(java.lang.String name)
Get a child by its name or path. |
XMLElement |
getChildAtIndex(int index)
Returns the child at a specific index. |
int |
getChildCount()
Returns the number of children. |
XMLElement[] |
getChildren()
Returns an array containing all the child elements. |
XMLElement[] |
getChildren(java.lang.String name)
Get any children that match this name or path. |
java.lang.String |
getContent()
Return the #PCDATA content of the element. |
double |
getDoubleAttribute(java.lang.String name)
|
double |
getDoubleAttribute(java.lang.String name,
double defaultValue)
Returns the value of an attribute. |
double |
getDoubleAttribute(java.lang.String name,
java.lang.String namespace,
double defaultValue)
Returns the value of an attribute. |
float |
getFloatAttribute(java.lang.String name)
|
float |
getFloatAttribute(java.lang.String name,
float defaultValue)
Returns the value of an attribute. |
float |
getFloatAttribute(java.lang.String name,
java.lang.String namespace,
float defaultValue)
Returns the value of an attribute. |
int |
getIntAttribute(java.lang.String name)
|
int |
getIntAttribute(java.lang.String name,
int defaultValue)
Returns the value of an attribute. |
int |
getIntAttribute(java.lang.String name,
java.lang.String namespace,
int defaultValue)
Returns the value of an attribute. |
int |
getLineNr()
Returns the line number in the data where the element started. |
java.lang.String |
getLocalName()
Returns the name of the element. |
java.lang.String |
getName()
Returns the full name (i.e. |
java.lang.String |
getNamespace()
Returns the namespace of the element. |
XMLElement |
getParent()
Returns the parent element. |
java.lang.String |
getStringAttribute(java.lang.String name)
|
java.lang.String |
getStringAttribute(java.lang.String name,
java.lang.String defaultValue)
|
java.lang.String |
getStringAttribute(java.lang.String name,
java.lang.String namespace,
java.lang.String defaultValue)
|
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. |
void |
insertChild(XMLElement child,
int index)
Inserts a child element. |
boolean |
isLeaf()
Returns whether the element is a leaf element. |
java.lang.String[] |
listChildren()
Put the names of all children into an array. |
void |
removeAttribute(java.lang.String name)
Removes an attribute. |
void |
removeAttribute(java.lang.String name,
java.lang.String namespace)
Removes an attribute. |
void |
removeChild(XMLElement 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. |
java.lang.String |
toString(boolean pretty)
|
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NO_LINE
Constructor Detail |
---|
public XMLElement()
public XMLElement(java.lang.String fullName, java.lang.String namespace, java.lang.String systemID, int lineNr)
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.public XMLElement(PApplet parent, java.lang.String filename)
filename
- parent
- public XMLElement(java.io.Reader r)
public XMLElement(java.lang.String xml)
Method Detail |
---|
public XMLElement createPCDataElement()
public XMLElement createElement(java.lang.String fullName, java.lang.String namespace)
fullName
- the full name of the elementnamespace
- the namespace URI.public XMLElement createElement(java.lang.String fullName, java.lang.String namespace, java.lang.String systemID, int lineNr)
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.public XMLElement getParent()
public java.lang.String getName()
public java.lang.String getLocalName()
public java.lang.String getNamespace()
public void setName(java.lang.String name)
name
- the non-null name.public void setName(java.lang.String fullName, java.lang.String namespace)
fullName
- the non-null full name.namespace
- the namespace URI, which may be null.public void addChild(XMLElement child)
child
- the non-null child to add.public void insertChild(XMLElement child, int index)
child
- the non-null child to add.index
- where to put the child.public void removeChild(XMLElement child)
child
- the non-null child to remove.public void removeChildAtIndex(int index)
index
- the index of the child, where the first child has index 0.public java.util.Enumeration<XMLElement> enumerateChildren()
public boolean isLeaf()
public boolean hasChildren()
public int getChildCount()
public java.lang.String[] listChildren()
public XMLElement[] getChildren()
public XMLElement getChild(int which)
public XMLElement getChild(java.lang.String name)
name
- element name or path/to/element
public XMLElement getChildAtIndex(int index) throws java.lang.ArrayIndexOutOfBoundsException
index
- the index of the child
java.lang.ArrayIndexOutOfBoundsException
- if the index is out of bounds.public XMLElement[] getChildren(java.lang.String name)
name
- element name or path/to/element
public int getAttributeCount()
public java.lang.String getAttribute(java.lang.String name)
name
- the non-null name of the attribute.
public java.lang.String getAttribute(java.lang.String name, java.lang.String defaultValue)
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.
public java.lang.String getAttribute(java.lang.String name, java.lang.String namespace, java.lang.String defaultValue)
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.defaultValue
- the default value of the attribute.
public java.lang.String getStringAttribute(java.lang.String name)
public java.lang.String getStringAttribute(java.lang.String name, java.lang.String defaultValue)
public java.lang.String getStringAttribute(java.lang.String name, java.lang.String namespace, java.lang.String defaultValue)
public int getIntAttribute(java.lang.String name)
public int getIntAttribute(java.lang.String name, int defaultValue)
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.
public int getIntAttribute(java.lang.String name, java.lang.String namespace, int defaultValue)
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.defaultValue
- the default value of the attribute.
public float getFloatAttribute(java.lang.String name)
public float getFloatAttribute(java.lang.String name, float defaultValue)
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.
public float getFloatAttribute(java.lang.String name, java.lang.String namespace, float defaultValue)
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.defaultValue
- the default value of the attribute.
public double getDoubleAttribute(java.lang.String name)
public double getDoubleAttribute(java.lang.String name, double defaultValue)
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.
public double getDoubleAttribute(java.lang.String name, java.lang.String namespace, double defaultValue)
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.defaultValue
- the default value of the attribute.
public java.lang.String getAttributeType(java.lang.String name)
name
- the non-null full name of the attribute.
public java.lang.String getAttributeNamespace(java.lang.String name)
name
- the non-null full name of the attribute.
public java.lang.String getAttributeType(java.lang.String name, java.lang.String namespace)
name
- the non-null name of the attribute.namespace
- the namespace URI, which may be null.
public void setAttribute(java.lang.String name, java.lang.String value)
name
- the non-null full name of the attribute.value
- the non-null value of the attribute.public void setAttribute(java.lang.String fullName, java.lang.String namespace, java.lang.String value)
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.public void removeAttribute(java.lang.String name)
name
- the non-null name of the attribute.public void removeAttribute(java.lang.String name, java.lang.String namespace)
name
- the non-null name of the attribute.namespace
- the namespace URI of the attribute, which may be null.public java.util.Enumeration<java.lang.String> enumerateAttributeNames()
public boolean hasAttribute(java.lang.String name)
public boolean hasAttribute(java.lang.String name, java.lang.String namespace)
public java.util.Properties getAttributes()
public java.util.Properties getAttributesInNamespace(java.lang.String namespace)
namespace
- the namespace URI of the attributes, which may be null.
public java.lang.String getSystemID()
getLineNr()
public int getLineNr()
NO_LINE
,
getSystemID()
public java.lang.String getContent()
public void setContent(java.lang.String content)
content
- the (possibly null) content.public boolean equals(java.lang.Object rawElement)
equals
in class java.lang.Object
rawElement
- the element to compare topublic boolean equalsXMLElement(XMLElement rawElement)
rawElement
- the element to compare topublic java.lang.String toString(boolean pretty)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |