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