Package gw.xml.simple
Class SimpleXmlNode
java.lang.Object
gw.xml.simple.SimpleXmlNode
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<SimpleXmlNode>
private String
private SimpleXmlNode
private String
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleXmlNode
(String name) Construct a new SimpleXmlNode with the given element name. -
Method Summary
Modifier and TypeMethodDescriptiondeepCopy()
Makes a deep copy of this node, including copies of all contained children.Returns the attributes associated with this node.Returns the immediate children of this node.Returns an Iterable over the descendents of this node (not including this node).getName()
Returns the name of this node.Returns the parent of this node, or null if this node is a root node.getText()
Returns the textual content of this node, if any.static SimpleXmlNode
Parse the given File to create a SimpleXmlNode.static SimpleXmlNode
parse
(InputStream is) Parse the given InputStream to create a SimpleXmlNode.static SimpleXmlNode
Parse the given String to create a SimpleXmlNode.void
Sets the name of this node.(package private) void
setParent
(SimpleXmlNode parent) void
Sets the text content of this node.Makes a shallow copy of this node, including its name, text, and attributes.Returns a version of this node, including all its children, as a valid XML String.
-
Field Details
-
_children
-
_attributes
-
_name
-
_text
-
_parent
-
-
Constructor Details
-
SimpleXmlNode
Construct a new SimpleXmlNode with the given element name. The name cannot be null and should be a valid XML element name.- Parameters:
name
- the name of the node
-
-
Method Details
-
parse
Parse the given String to create a SimpleXmlNode.- Parameters:
s
- the XML content to be parsed- Returns:
- the resulting SimpleXmlNode
-
parse
Parse the given File to create a SimpleXmlNode.- Parameters:
f
- the File containing XML content to be parsed- Returns:
- the resulting SimpleXmlNode
-
parse
Parse the given InputStream to create a SimpleXmlNode.- Parameters:
is
- the InputStream containing XML content to be parsed- Returns:
- the resulting SimpleXmlNode
-
getChildren
Returns the immediate children of this node. Adding or removing to this list will automatically set or null out the Parent on the node being added or removed.- Returns:
- the children of this node
-
getDescendents
Returns an Iterable over the descendents of this node (not including this node). Descendents are traversed in pre-order.- Returns:
- a pre-ordered iterator over the descendents of this node
-
getAttributes
Returns the attributes associated with this node. Note that all prefixes are removed from attribute names during parsing, so the XML foo:bar="xyz" will result in an entry in this map with the key "bar" and the value "xyz".- Returns:
- the map of attributes for this node.
-
getName
Returns the name of this node.- Returns:
- the name of this node
-
setName
Sets the name of this node. The name cannot be null, and should be a legal XML element identifier.- Parameters:
name
- the new name
-
getText
Returns the textual content of this node, if any. This property may return null in the event that the element has no text content.- Returns:
- the text content of this node
-
setText
Sets the text content of this node.- Parameters:
text
- the text content for the node
-
getParent
Returns the parent of this node, or null if this node is a root node. This property is set automatically when a node is added to the child list of another node, and nulled out automatically when the node is removed from the child list of its parent. It cannot be set explicitly.- Returns:
- the parent of this node
-
setParent
-
shallowCopy
Makes a shallow copy of this node, including its name, text, and attributes. The returned node will have no children and no parent.- Returns:
- a shallow copy of this node
-
deepCopy
Makes a deep copy of this node, including copies of all contained children. The returned node will have the same name, text, and attributes as this node, and its list of children will contain deep copies of each child of this node.- Returns:
- a deep copy of this node
-
toXmlString
Returns a version of this node, including all its children, as a valid XML String.- Returns:
- a String containing the XML for this node and its children
-