Package gw.xml.simple

Class SimpleXmlNode

java.lang.Object
gw.xml.simple.SimpleXmlNode

public class SimpleXmlNode extends Object
  • Field Details

  • Constructor Details

    • SimpleXmlNode

      public SimpleXmlNode(String name)
      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

      public static SimpleXmlNode parse(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(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(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 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 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 Map<String,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 String getName()
      Returns the name of this node.
      Returns:
      the name of this node
    • setName

      public void setName(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 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(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 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