Documentation of 'processing.data.XML' Java class
XML
processing.data

Class XML

    • Constructor Summary

      Constructors 
      Constructor and Description
      XML(java.io.File file)
      Advanced users only; use loadXML() in PApplet.
      XML(java.io.File file, java.lang.String options)
      Advanced users only; use loadXML() in PApplet.
      XML(java.io.InputStream input) 
      XML(java.io.InputStream input, java.lang.String options)
      Unlike the loadXML() method in PApplet, this version works with files that are not in UTF-8 format.
      XML(java.io.Reader reader)
      Advanced users only; use loadXML() in PApplet.
      XML(java.io.Reader reader, java.lang.String options)
      Advanced users only; use loadXML() in PApplet.
      XML(java.lang.String name) 
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      XML addChild(java.lang.String tag) 
      XML addChild(XML child) 
      java.lang.String format(int indent)
      Format this XML data as a String.
      int getAttributeCount()
      Returns the number of attributes.
      XML getChild(int index)
      Quick accessor for an element at a particular index.
      XML getChild(java.lang.String name)
      Get a child by its name or path.
      int getChildCount()
      Returns the number of children.
      XML[] getChildren()
      Returns an array containing all the child elements.
      XML[] getChildren(java.lang.String name)
      Get any children that match this name or path.
      java.lang.String getContent()
      Return the #PCDATA content of the element.
      java.lang.String getContent(java.lang.String defaultValue) 
      double getDouble(java.lang.String name) 
      double getDouble(java.lang.String name, double defaultValue)
      Returns the value of an attribute.
      double getDoubleContent() 
      double getDoubleContent(double defaultValue) 
      float getFloat(java.lang.String name)
      Returns the value of an attribute, or zero if not present.
      float getFloat(java.lang.String name, float defaultValue)
      Returns the value of an attribute.
      float getFloatContent() 
      float getFloatContent(float defaultValue) 
      int getInt(java.lang.String name) 
      int getInt(java.lang.String name, int defaultValue)
      Returns the value of an attribute.
      int getIntContent() 
      int getIntContent(int defaultValue) 
      java.lang.String getLocalName()
      Returns the name of the element (without namespace prefix).
      long getLong(java.lang.String name, long defaultValue)
      Returns the value of an attribute.
      long getLongContent() 
      long getLongContent(long defaultValue) 
      java.lang.String getName()
      Returns the full name (i.e.
      XML getParent()
      Returns the parent element.
      java.lang.String getString(java.lang.String name) 
      java.lang.String getString(java.lang.String name, java.lang.String defaultValue) 
      boolean hasAttribute(java.lang.String name)
      Returns whether an attribute exists.
      boolean hasChildren()
      Returns a boolean of whether or not there are children.
      java.lang.String[] listAttributes()
      Get a list of the names for all of the attributes for this node.
      java.lang.String[] listChildren()
      Put the names of all children into an array.
      static XML parse(java.lang.String data) 
      static XML parse(java.lang.String data, java.lang.String options) 
      void removeChild(XML kid) 
      boolean save(java.io.File file) 
      boolean save(java.io.File file, java.lang.String options) 
      void setContent(java.lang.String text) 
      void setDouble(java.lang.String name, double value) 
      void setDoubleContent(double value) 
      void setFloat(java.lang.String name, float value) 
      void setFloatContent(float value) 
      void setInt(java.lang.String name, int value) 
      void setIntContent(int value) 
      void setLong(java.lang.String name, long value) 
      void setLongContent(long value) 
      void setName(java.lang.String newName) 
      void setString(java.lang.String name, java.lang.String value) 
      java.lang.String toString()
      Return the XML document formatted with two spaces for indents.
      void trim() 
      boolean write(java.io.PrintWriter output) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • XML

        public XML(java.io.File file)
            throws java.io.IOException,
                   javax.xml.parsers.ParserConfigurationException,
                   org.xml.sax.SAXException
        Advanced users only; use loadXML() in PApplet. This is not a supported function and is subject to change. It is available simply for users that would like to handle the exceptions in a particular way.
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • XML

        public XML(java.io.File file,
                   java.lang.String options)
            throws java.io.IOException,
                   javax.xml.parsers.ParserConfigurationException,
                   org.xml.sax.SAXException
        Advanced users only; use loadXML() in PApplet.
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • XML

        public XML(java.io.InputStream input)
            throws java.io.IOException,
                   javax.xml.parsers.ParserConfigurationException,
                   org.xml.sax.SAXException
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • XML

        public XML(java.io.InputStream input,
                   java.lang.String options)
            throws java.io.IOException,
                   javax.xml.parsers.ParserConfigurationException,
                   org.xml.sax.SAXException
        Unlike the loadXML() method in PApplet, this version works with files that are not in UTF-8 format.
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • XML

        public XML(java.io.Reader reader)
            throws java.io.IOException,
                   javax.xml.parsers.ParserConfigurationException,
                   org.xml.sax.SAXException
        Advanced users only; use loadXML() in PApplet.
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • XML

        public XML(java.io.Reader reader,
                   java.lang.String options)
            throws java.io.IOException,
                   javax.xml.parsers.ParserConfigurationException,
                   org.xml.sax.SAXException
        Advanced users only; use loadXML() in PApplet. Added extra code to handle 
 (Unicode NLF), which is sometimes inserted by web browsers (Safari?) and not distinguishable from a "real" LF (or CRLF) in some text editors (i.e. TextEdit on OS X). Only doing this for XML (and not all Reader objects) because LFs are essential. https://github.com/processing/processing/issues/2100
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • XML

        public XML(java.lang.String name)
        Parameters:
        name - creates a node with this name
    • Method Detail

      • parse

        public static XML parse(java.lang.String data)
                         throws java.io.IOException,
                                javax.xml.parsers.ParserConfigurationException,
                                org.xml.sax.SAXException
        Parameters:
        data - the content to be parsed as XML
        Returns:
        an XML object, or null
        Throws:
        org.xml.sax.SAXException
        javax.xml.parsers.ParserConfigurationException
        java.io.IOException
      • parse

        public static XML parse(java.lang.String data,
                                java.lang.String options)
                         throws java.io.IOException,
                                javax.xml.parsers.ParserConfigurationException,
                                org.xml.sax.SAXException
        Throws:
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
        org.xml.sax.SAXException
      • save

        public boolean save(java.io.File file)
      • save

        public boolean save(java.io.File file,
                            java.lang.String options)
      • write

        public boolean write(java.io.PrintWriter output)
      • getParent

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

        public java.lang.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(java.lang.String newName)
      • getLocalName

        public java.lang.String getLocalName()
        Returns the name of the element (without namespace prefix). 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 java.lang.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(java.lang.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
      • getChildren

        public XML[] getChildren(java.lang.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
      • addChild

        public XML addChild(java.lang.String tag)
      • addChild

        public XML addChild(XML child)
      • removeChild

        public void removeChild(XML kid)
      • trim

        public void trim()
      • getAttributeCount

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

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

        public boolean hasAttribute(java.lang.String name)
        Returns whether an attribute exists.
      • getString

        public java.lang.String getString(java.lang.String name)
      • getString

        public java.lang.String getString(java.lang.String name,
                                          java.lang.String defaultValue)
      • setString

        public void setString(java.lang.String name,
                              java.lang.String value)
      • getInt

        public int getInt(java.lang.String name)
      • setInt

        public void setInt(java.lang.String name,
                           int value)
      • getInt

        public int getInt(java.lang.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(java.lang.String name,
                            long value)
      • getLong

        public long getLong(java.lang.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(java.lang.String name)
        Returns the value of an attribute, or zero if not present.
      • getFloat

        public float getFloat(java.lang.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(java.lang.String name,
                             float value)
      • getDouble

        public double getDouble(java.lang.String name)
      • getDouble

        public double getDouble(java.lang.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(java.lang.String name,
                              double value)
      • getContent

        public java.lang.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 java.lang.String getContent(java.lang.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(java.lang.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 java.lang.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()
      • toString

        public java.lang.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 java.lang.Object
        Returns:
        the content
        See Also:
        format(int)

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.