public class XML
extends java.lang.Object
implements java.io.Serializable
Constructor and Description |
---|
XML(java.io.File file)
Advanced users only; use loadXML() in PApplet.
|
XML(java.io.File file,
java.lang.String options)
Advanced users only; use loadXML() in PApplet.
|
XML(java.io.InputStream input) |
XML(java.io.InputStream input,
java.lang.String options)
Unlike the loadXML() method in PApplet, this version works with files
that are not in UTF-8 format.
|
XML(java.io.Reader reader)
Advanced users only; use loadXML() in PApplet.
|
XML(java.io.Reader reader,
java.lang.String options)
Advanced users only; use loadXML() in PApplet.
|
XML(java.lang.String name) |
Modifier and Type | Method and Description |
---|---|
XML |
addChild(java.lang.String tag) |
XML |
addChild(XML child) |
java.lang.String |
format(int indent)
Format this XML data as a String.
|
int |
getAttributeCount()
Returns the number of attributes.
|
XML |
getChild(int index)
Quick accessor for an element at a particular index.
|
XML |
getChild(java.lang.String name)
Get a child by its name or path.
|
int |
getChildCount()
Returns the number of children.
|
XML[] |
getChildren()
Returns an array containing all the child elements.
|
XML[] |
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.
|
java.lang.String |
getContent(java.lang.String defaultValue) |
double |
getDouble(java.lang.String name) |
double |
getDouble(java.lang.String name,
double defaultValue)
Returns the value of an attribute.
|
double |
getDoubleContent() |
double |
getDoubleContent(double defaultValue) |
float |
getFloat(java.lang.String name)
Returns the value of an attribute, or zero if not present.
|
float |
getFloat(java.lang.String name,
float defaultValue)
Returns the value of an attribute.
|
float |
getFloatContent() |
float |
getFloatContent(float defaultValue) |
int |
getInt(java.lang.String name) |
int |
getInt(java.lang.String name,
int defaultValue)
Returns the value of an attribute.
|
int |
getIntContent() |
int |
getIntContent(int defaultValue) |
java.lang.String |
getLocalName()
Returns the name of the element (without namespace prefix).
|
long |
getLong(java.lang.String name,
long defaultValue)
Returns the value of an attribute.
|
long |
getLongContent() |
long |
getLongContent(long defaultValue) |
java.lang.String |
getName()
Returns the full name (i.e.
|
XML |
getParent()
Returns the parent element.
|
java.lang.String |
getString(java.lang.String name) |
java.lang.String |
getString(java.lang.String name,
java.lang.String defaultValue) |
boolean |
hasAttribute(java.lang.String name)
Returns whether an attribute exists.
|
boolean |
hasChildren()
Returns a boolean of whether or not there are children.
|
java.lang.String[] |
listAttributes()
Get a list of the names for all of the attributes for this node.
|
java.lang.String[] |
listChildren()
Put the names of all children into an array.
|
static XML |
parse(java.lang.String data) |
static XML |
parse(java.lang.String data,
java.lang.String options) |
void |
print() |
void |
removeChild(XML kid) |
boolean |
save(java.io.File file) |
boolean |
save(java.io.File file,
java.lang.String options) |
void |
setContent(java.lang.String text) |
void |
setDouble(java.lang.String name,
double value) |
void |
setDoubleContent(double value) |
void |
setFloat(java.lang.String name,
float value) |
void |
setFloatContent(float value) |
void |
setInt(java.lang.String name,
int value) |
void |
setIntContent(int value) |
void |
setLong(java.lang.String name,
long value) |
void |
setLongContent(long value) |
void |
setName(java.lang.String newName) |
void |
setString(java.lang.String name,
java.lang.String value) |
java.lang.String |
toString()
Return the XML document formatted with two spaces for indents.
|
void |
trim()
Removes whitespace nodes.
|
boolean |
write(java.io.PrintWriter output) |
public XML(java.io.File file) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public XML(java.io.File file, java.lang.String options) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public XML(java.io.InputStream input) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public XML(java.io.InputStream input, java.lang.String options) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public XML(java.io.Reader reader) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public XML(java.io.Reader reader, java.lang.String options) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public XML(java.lang.String name)
name
- creates a node with this namepublic static XML parse(java.lang.String data) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
data
- the content to be parsed as XMLorg.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
java.io.IOException
public static XML parse(java.lang.String data, java.lang.String options) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
public boolean save(java.io.File file)
public boolean save(java.io.File file, java.lang.String options)
public boolean write(java.io.PrintWriter output)
public XML getParent()
public java.lang.String getName()
public void setName(java.lang.String newName)
public java.lang.String getLocalName()
public int getChildCount()
public boolean hasChildren()
public java.lang.String[] listChildren()
public XML[] getChildren()
public XML getChild(int index)
public XML getChild(java.lang.String name)
name
- element name or path/to/elementpublic XML[] getChildren(java.lang.String name)
name
- element name or path/to/elementpublic XML addChild(java.lang.String tag)
public void removeChild(XML kid)
public void trim()
public int getAttributeCount()
public java.lang.String[] listAttributes()
public boolean hasAttribute(java.lang.String name)
public java.lang.String getString(java.lang.String name)
public java.lang.String getString(java.lang.String name, java.lang.String defaultValue)
public void setString(java.lang.String name, java.lang.String value)
public int getInt(java.lang.String name)
public void setInt(java.lang.String name, int value)
public int getInt(java.lang.String name, int defaultValue)
name
- the non-null full name of the attributedefaultValue
- the default value of the attributepublic void setLong(java.lang.String name, long value)
public long getLong(java.lang.String name, long defaultValue)
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.public float getFloat(java.lang.String name)
public float getFloat(java.lang.String name, float defaultValue)
name
- the non-null full name of the attribute.defaultValue
- the default value of the attribute.public void setFloat(java.lang.String name, float value)
public double getDouble(java.lang.String name)
public double getDouble(java.lang.String name, double defaultValue)
name
- the non-null full name of the attributedefaultValue
- the default value of the attributepublic void setDouble(java.lang.String name, double value)
public java.lang.String getContent()
getIntContent()
,
getFloatContent()
public java.lang.String getContent(java.lang.String defaultValue)
public int getIntContent()
getContent()
,
getFloatContent()
public int getIntContent(int defaultValue)
defaultValue
- the default value of the attributepublic float getFloatContent()
getContent()
,
getIntContent()
public float getFloatContent(float defaultValue)
defaultValue
- the default value of the attributepublic long getLongContent()
public long getLongContent(long defaultValue)
public double getDoubleContent()
public double getDoubleContent(double defaultValue)
public void setContent(java.lang.String text)
public void setIntContent(int value)
public void setFloatContent(float value)
public void setLongContent(long value)
public void setDoubleContent(double value)
public java.lang.String format(int indent)
indent
- -1 for a single line (and no declaration), >= 0 for indents and newlinestoString()
public void print()
public java.lang.String toString()
toString
in class java.lang.Object
format(int)