public class Node extends Object
Node is a data structure representing a container in a classic tree. May sometimes be synonymous with the
term "Element" in XML. It may contain a Map of attributes (Strings), a reference to a List of
child Nodes, and text data.| Constructor and Description |
|---|
Node(String name)
Creates a root
Node |
Node(String name,
Node parent)
Creates a
Node |
| Modifier and Type | Method and Description |
|---|---|
Node |
attribute(String name,
Object value)
Add or override a named attribute.
value will be converted to String using String.valueOf(value); |
Node |
attribute(String name,
String value)
Add or override a named attribute.
|
Node |
createChild(String name)
Create a new
Node with given name. |
List<Node> |
get(String name)
Get all children with a specific name.
|
String |
getAttribute(String name)
Get a named attribute.
|
Map<String,String> |
getAttributes()
Get all defined attributes for this Node in an immutable view
|
List<Node> |
getChildren()
Get all the defined children for this node in an immutable view.
|
String |
getName()
Get the Nodes name.
|
Node |
getOrCreate(String name)
Get or create a named child node.
|
Node |
getParent()
Get the Nodes parent.
|
Node |
getRoot()
Obtains the root
Node for this reference |
Node |
getSingle(String name)
Get a single child node.
If multiple children are found with same name it is considered a IllegalArgumentException. |
String |
getText()
Get the Nodes text body.
|
String |
getTextValueForPatternName(String name)
Get the text value of the element found at the given query name.
|
List<String> |
getTextValuesForPatternName(String name)
Get the text values of all elements found at the given query name.
|
boolean |
isComment()
Returns whether or not this
Node represents a comment |
boolean |
isRoot()
Returns whether or not this
Node is a root |
String |
removeAttribute(String name)
Remove a named attribute.
|
boolean |
removeChild(Node child)
Remove a single child from this
Node |
Node |
removeChild(String name)
Remove a single child from this
Node |
List<Node> |
removeChildren(String name)
Remove all child nodes found at the given query.
|
void |
setComment(boolean comment)
Marks this
Node as a comment |
Node |
text(Object text)
Set the Nodes text body.
text will be converted to String using String.valueOf(text); |
Node |
text(String text)
Set the Nodes text body.
|
String |
toString() |
String |
toString(boolean verbose)
|
public Node(String name) throws IllegalArgumentException
Nodename - The name of the nodeIllegalArgumentExceptionpublic Node(String name, Node parent) throws IllegalArgumentException
Nodename - The name of the nodeparent - The parent node. Use null to denote a root.IllegalArgumentException - If the name is not specified or contains any space characterspublic Node attribute(String name, Object value)
name - The attribute namevalue - The given valueNodeattribute(String, String)public Node attribute(String name, String value)
name - The attribute namevalue - The given valueNodepublic String getAttribute(String name)
name - The attribute namepublic String removeAttribute(String name) throws IllegalArgumentException
name - The attribute nameIllegalArgumentException - If the name is not specifiedpublic Map<String,String> getAttributes()
public boolean isComment()
Node represents a commentpublic void setComment(boolean comment)
throws IllegalArgumentException
Node as a commentcomment - Whether or not this is a commentIllegalArgumentException - If this node has childrenpublic boolean isRoot()
Node is a rootpublic Node createChild(String name) throws IllegalArgumentException
name - The name of the Node.NodeIllegalArgumentException - If the name is not specifiedpublic Node getOrCreate(String name)
getSingle(String) it is returned, else a new child node is created.name - The child node name.IllegalArgumentException - if multiple children with name exists.getSingle(String),
createChild(String)public Node getSingle(String name)
name - The child node nameIllegalArgumentException - if multiple children with name exists.public List<Node> get(String name)
name - The child node name.public List<Node> removeChildren(String name) throws IllegalArgumentException
List of removed children.IllegalArgumentException - If the specified name is not specifiedpublic boolean removeChild(Node child)
Nodepublic Node removeChild(String name)
NodeIllegalArgumentException - if multiple children with name exist.public Node text(Object text)
text - text(String)public Node text(String text)
text - The text contentpublic String getText()
public String getTextValueForPatternName(String name)
public List<String> getTextValuesForPatternName(String name)
public String getName()
public Node getParent()
public List<Node> getChildren()
public String toString()
toString in class ObjectObject.toString()public String toString(boolean verbose)
verbose - Copyright © 2013 JBoss by Red Hat. All Rights Reserved.