Package gw.xml.simple
Class SimpleXmlNode
- java.lang.Object
-
- gw.xml.simple.SimpleXmlNode
-
public class SimpleXmlNode extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>_attributesprivate java.util.List<SimpleXmlNode>_childrenprivate java.lang.String_nameprivate SimpleXmlNode_parentprivate java.lang.String_text
-
Constructor Summary
Constructors Constructor Description SimpleXmlNode(java.lang.String name)Construct a new SimpleXmlNode with the given element name.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleXmlNodedeepCopy()Makes a deep copy of this node, including copies of all contained children.java.util.Map<java.lang.String,java.lang.String>getAttributes()Returns the attributes associated with this node.java.util.List<SimpleXmlNode>getChildren()Returns the immediate children of this node.java.lang.Iterable<SimpleXmlNode>getDescendents()Returns an Iterable over the descendents of this node (not including this node).java.lang.StringgetName()Returns the name of this node.SimpleXmlNodegetParent()Returns the parent of this node, or null if this node is a root node.java.lang.StringgetText()Returns the textual content of this node, if any.static SimpleXmlNodeparse(java.io.File f)Parse the given File to create a SimpleXmlNode.static SimpleXmlNodeparse(java.io.InputStream is)Parse the given InputStream to create a SimpleXmlNode.static SimpleXmlNodeparse(java.lang.String s)Parse the given String to create a SimpleXmlNode.voidsetName(java.lang.String name)Sets the name of this node.(package private) voidsetParent(SimpleXmlNode parent)voidsetText(java.lang.String text)Sets the text content of this node.SimpleXmlNodeshallowCopy()Makes a shallow copy of this node, including its name, text, and attributes.java.lang.StringtoXmlString()Returns a version of this node, including all its children, as a valid XML String.
-
-
-
Field Detail
-
_children
private java.util.List<SimpleXmlNode> _children
-
_attributes
private java.util.Map<java.lang.String,java.lang.String> _attributes
-
_name
private java.lang.String _name
-
_text
private java.lang.String _text
-
_parent
private SimpleXmlNode _parent
-
-
Method Detail
-
parse
public static SimpleXmlNode parse(java.lang.String s)
Parse the given String to create a SimpleXmlNode.- Parameters:
s- the XML content to be parsed- Returns:
- the resulting SimpleXmlNode
-
parse
public static SimpleXmlNode parse(java.io.File f)
Parse the given File to create a SimpleXmlNode.- Parameters:
f- the File containing XML content to be parsed- Returns:
- the resulting SimpleXmlNode
-
parse
public static SimpleXmlNode parse(java.io.InputStream is)
Parse the given InputStream to create a SimpleXmlNode.- Parameters:
is- the InputStream containing XML content to be parsed- Returns:
- the resulting SimpleXmlNode
-
getChildren
public java.util.List<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
public java.lang.Iterable<SimpleXmlNode> 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
public java.util.Map<java.lang.String,java.lang.String> 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
public java.lang.String getName()
Returns the name of this node.- Returns:
- the name of this node
-
setName
public void setName(java.lang.String name)
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
public java.lang.String 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
public void setText(java.lang.String text)
Sets the text content of this node.- Parameters:
text- the text content for the node
-
getParent
public SimpleXmlNode 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
void setParent(SimpleXmlNode parent)
-
shallowCopy
public SimpleXmlNode 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
public SimpleXmlNode 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
public java.lang.String 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
-
-