Class XML

    • Field Detail

      • node

        protected Node node
        The internal representation, a DOM node.
      • parent

        protected XML parent
        The parent element.
      • children

        protected XML[] children
        Child elements, once loaded.
    • Method Detail

      • save

        public boolean save​(File file)
      • save

        public boolean save​(File file,
                            String options)
      • getParent

        public XML getParent()
        Returns the parent element. This method returns null for the root element.
      • getNative

        protected Object getNative()
        Internal function; not included in reference.
      • getName

        public String getName()
        Returns the full name (i.e. the name including an eventual namespace prefix) of the element.
        Returns:
        the name, or null if the element only contains #PCDATA.
      • setName

        public void setName​(String newName)
      • getLocalName

        public String getLocalName()
        Returns the name of the element (without namespace prefix). Internal function; not included in reference.
      • checkChildren

        protected void checkChildren()
        Honey, can you just check on the kids? Thanks. Internal function; not included in reference.
      • getChildCount

        public int getChildCount()
        Returns the number of children.
        Returns:
        the count.
      • hasChildren

        public boolean hasChildren()
        Returns a boolean of whether or not there are children.
      • listChildren

        public String[] listChildren()
        Put the names of all children into an array. Same as looping through each child and calling getName() on each XMLElement.
      • getChildren

        public XML[] getChildren()
        Returns an array containing all the child elements.
      • getChild

        public XML getChild​(int index)
        Quick accessor for an element at a particular index.
      • getChild

        public XML getChild​(String name)
        Get a child by its name or path.
        Parameters:
        name - element name or path/to/element
        Returns:
        the first matching element or null if no match
      • getChildRecursive

        protected XML getChildRecursive​(String[] items,
                                        int offset)
        Internal helper function for getChild(String).
        Parameters:
        items - result of splitting the query on slashes
        offset - where in the items[] array we're currently looking
        Returns:
        matching element or null if no match
      • getChildren

        public XML[] getChildren​(String name)
        Get any children that match this name or path. Similar to getChild(), but will grab multiple matches rather than only the first.
        Parameters:
        name - element name or path/to/element
        Returns:
        array of child elements that match
      • getChildrenRecursive

        protected XML[] getChildrenRecursive​(String[] items,
                                             int offset)
      • addChild

        public XML addChild​(String tag)
      • addChild

        public XML addChild​(XML child)
      • appendChild

        protected XML appendChild​(Node newNode)
        Internal handler to add the node structure.
      • removeChild

        public void removeChild​(XML kid)
      • trim

        public void trim()
        Removes whitespace nodes. Those whitespace nodes are required to reconstruct the original XML's spacing and indentation. If you call this and use saveXML() your original spacing will be gone.
      • getAttributeCount

        public int getAttributeCount()
        Returns the number of attributes.
      • listAttributes

        public String[] listAttributes()
        Get a list of the names for all of the attributes for this node.
      • hasAttribute

        public boolean hasAttribute​(String name)
        Returns whether an attribute exists.
      • setString

        public void setString​(String name,
                              String value)
      • getInt

        public int getInt​(String name)
      • setInt

        public void setInt​(String name,
                           int value)
      • getInt

        public int getInt​(String name,
                          int defaultValue)
        Returns the value of an attribute.
        Parameters:
        name - the non-null full name of the attribute
        defaultValue - the default value of the attribute
        Returns:
        the value, or defaultValue if the attribute does not exist
      • setLong

        public void setLong​(String name,
                            long value)
      • getLong

        public long getLong​(String name,
                            long defaultValue)
        Returns the value of an attribute.
        Parameters:
        name - the non-null full name of the attribute.
        defaultValue - the default value of the attribute.
        Returns:
        the value, or defaultValue if the attribute does not exist.
      • getFloat

        public float getFloat​(String name)
        Returns the value of an attribute, or zero if not present.
      • getFloat

        public float getFloat​(String name,
                              float defaultValue)
        Returns the value of an attribute.
        Parameters:
        name - the non-null full name of the attribute.
        defaultValue - the default value of the attribute.
        Returns:
        the value, or defaultValue if the attribute does not exist.
      • setFloat

        public void setFloat​(String name,
                             float value)
      • getDouble

        public double getDouble​(String name)
      • getDouble

        public double getDouble​(String name,
                                double defaultValue)
        Returns the value of an attribute.
        Parameters:
        name - the non-null full name of the attribute
        defaultValue - the default value of the attribute
        Returns:
        the value, or defaultValue if the attribute does not exist
      • setDouble

        public void setDouble​(String name,
                              double value)
      • getContent

        public String getContent()
        Return the #PCDATA content of the element. If the element has a combination of #PCDATA content and child elements, the #PCDATA sections can be retrieved as unnamed child objects. In this case, this method returns null.
        Returns:
        the content.
        See Also:
        getIntContent(), getFloatContent()
      • getContent

        public String getContent​(String defaultValue)
      • getIntContent

        public int getIntContent​(int defaultValue)
        Parameters:
        defaultValue - the default value of the attribute
      • getFloatContent

        public float getFloatContent​(float defaultValue)
        Parameters:
        defaultValue - the default value of the attribute
      • getLongContent

        public long getLongContent()
      • getLongContent

        public long getLongContent​(long defaultValue)
      • getDoubleContent

        public double getDoubleContent()
      • getDoubleContent

        public double getDoubleContent​(double defaultValue)
      • setContent

        public void setContent​(String text)
      • setIntContent

        public void setIntContent​(int value)
      • setFloatContent

        public void setFloatContent​(float value)
      • setLongContent

        public void setLongContent​(long value)
      • setDoubleContent

        public void setDoubleContent​(double value)
      • format

        public String format​(int indent)
        Format this XML data as a String.
        Parameters:
        indent - -1 for a single line (and no declaration), >= 0 for indents and newlines
        Returns:
        the content
        See Also:
        toString()
      • print

        public void print()
      • toString

        public String toString()
        Return the XML document formatted with two spaces for indents. Chosen to do this since it's the most common case (e.g. with println()). Same as format(2). Use the format() function for more options.
        Overrides:
        toString in class Object
        Returns:
        the content
        See Also:
        format(int)