public class SimpleXML extends Object
SimpleXML(String) and append new
nodes by calling append(String).| Constructor and Description |
|---|
SimpleXML()
Constructs a new XML node without a name.
|
SimpleXML(String name)
Constructs a new XML node with the specified name.
|
SimpleXML(String name,
String[] attributeNames,
String[] attributeValues)
Constructs a new XML node with the specified name and attributes.
|
SimpleXML(String name,
String attributeName,
String attributeValue)
Constructs a new XML node with the specified name and a single attribute.
|
| Modifier and Type | Method and Description |
|---|---|
SimpleXML |
append(SimpleXML newChild)
Appends the node with all its child nodes to this node and returns the
child node.
|
SimpleXML |
append(String nodeName)
Appends a new XML node with the specified name and returns the new node.
|
SimpleXML |
append(String nodeName,
String nodeValue)
Appends a new XML node with the specified name and value and returns the
new node.
|
static SimpleXML |
fromDocument(Document document)
Creates a SimpleXML node from the specified
Document. |
String |
getAttribute(String attributeName)
Returns the value of the attribute with the given name.
|
String |
getAttribute(String attributeName,
String defaultValue)
Returns the value of the attribute with the given name.
|
String[] |
getAttributeNames()
Returns all attributes’ names.
|
Document |
getDocument()
Creates a
Document from this node and all its child nodes. |
String |
getName()
Returns the name of this node.
|
SimpleXML |
getNode(String nodeName)
Returns the child node of this node with the specified name.
|
SimpleXML |
getNode(String[] nodeNames)
Returns the child node that is specified by the names.
|
SimpleXML[] |
getNodes()
Returns all child nodes of this node.
|
SimpleXML[] |
getNodes(String nodeName)
Returns all child nodes of this node with the specified name.
|
String |
getValue()
Returns the value of this node.
|
String |
getValue(String childName)
Returns the value of the first child node with the specified name.
|
String |
getValue(String childName,
String defaultValue)
Returns the value of the first child node with the specified name, or the
default value if there is no child node with the given name.
|
boolean |
hasAttribute(String attributeName)
Checks whether this node contains the attribute with the given name.
|
boolean |
hasNode(String nodeName)
Checks if this object has a child with the specified name.
|
boolean |
hasNodes()
Returns whether this node has any child nodes.
|
void |
remove(SimpleXML child)
Removes the specified child from this node.
|
void |
remove(String childName)
Removes the child with the specified name from this node.
|
void |
removeAll()
Removes all children from this node.
|
String |
removeAttribute(String attributeName)
Removes the attribute with the given name, returning its previous value.
|
void |
replace(SimpleXML childNode)
Replaces the child node that has the same name as the given node by the
given node.
|
void |
replace(String childName,
String value)
Replace the child node with the specified name by a new node with the
specified content.
|
void |
setAttribute(String attributeName,
String attributeValue)
Sets the value of an attribute.
|
SimpleXML |
setValue(String nodeValue)
Sets the value of this node.
|
public SimpleXML()
public SimpleXML(String name)
name - The name of the new nodepublic SimpleXML(String name, String attributeName, String attributeValue)
name - The name of the nodeattributeName - The name of the attributeattributeValue - The value of the attributepublic String[] getAttributeNames()
public String getAttribute(String attributeName)
attributeName - The name of the attribute to look uppublic String getAttribute(String attributeName, String defaultValue)
attributeName - The name of the attribute to look updefaultValue - The value to return if there is no attribute with the given
namepublic void setAttribute(String attributeName, String attributeValue)
attributeName - The name of the attribute to setattributeValue - The value of the attributepublic String removeAttribute(String attributeName)
attributeName - The name of the attribute to removepublic boolean hasAttribute(String attributeName)
attributeName - The name of the attributetrue if this node has an attribute with the given
name, false otherwisepublic boolean hasNodes()
true if this node has child nodes, false
otherwisepublic boolean hasNode(String nodeName)
nodeName - The name of the child node to check fortrue if this node has at least one child with the
specified name, false otherwisepublic SimpleXML getNode(String nodeName)
nodeName - The name of the child nodenull if there is no child node
with the specified namepublic SimpleXML getNode(String[] nodeNames)
nodeNames is the name of the child node of this node, the
second element of nodeNames is the name of a child node's
child node, and so on. By using this method you can descend into an XML
tree pretty fast.
SimpleXML deepNode = topNode.getNodes(new String[] { "person", "address", "number" });
nodeNames - The names of the nodesnull if
the specified node does not eixstpublic SimpleXML[] getNodes()
public SimpleXML[] getNodes(String nodeName)
nodeName - The name of the nodes to retrieve, or null to
retrieve all nodespublic SimpleXML append(String nodeName)
SimpleXML mouseNode = topNode.append("computer").append("bus").append("usb").append("mouse");
nodeName - The name of the node to append as a child to this nodepublic SimpleXML append(String nodeName, String nodeValue)
nodeName - The name of the node to appendnodeValue - The value of the node to appendpublic SimpleXML append(SimpleXML newChild)
newChild - The node to append as a childpublic void remove(SimpleXML child)
child - The child to removepublic void remove(String childName)
childName - The name of the child node to removepublic void replace(String childName, String value)
childName - The name of the child to replacevalue - The node child's valuepublic void replace(SimpleXML childNode)
childNode - The node to replace the previous child node with the same namepublic void removeAll()
public SimpleXML setValue(String nodeValue)
nodeValue - The new value of this nodepublic String getName()
public String getValue()
public String getValue(String childName)
childName - The name of the child nodeNullPointerException - if the child node does not existpublic String getValue(String childName, String defaultValue)
childName - The name of the child nodedefaultValue - The default value to return if there is no child node with the
given nameNullPointerException - if the child node does not existpublic Document getDocument()
Document from this node and all its child nodes.Document created from this nodepublic static SimpleXML fromDocument(Document document)
Document. The
SimpleXML node of the document's top-level node is returned.document - The Document to create a SimpleXML node fromCopyright © 2026. All rights reserved.