Package nanoxml

Class XMLElement

java.lang.Object
nanoxml.XMLElement

public class XMLElement extends Object
XMLElement is a representation of an XML object. The object is able to parse XML code.

Parsing XML Data
You can parse XML data using the following code:
    XMLElement xml = new XMLElement();
    FileReader reader = new FileReader("filename.xml");
    xml.parseFromReader(reader);
Retrieving Attributes
You can enumerate the attributes of an element using the method enumerateAttributeNames. The attribute values can be retrieved using the method getStringAttribute. The following example shows how to list the attributes of an element:
    XMLElement element = ...;
    Enumeration enum = element.getAttributeNames();
    while (enum.hasMoreElements()) {
        String key = (String) enum.nextElement();
        String value = element.getStringAttribute(key);
        System.out.println(key + " = " + value);
    }
Retrieving Child Elements
You can enumerate the children of an element using enumerateChildren. The number of child elements can be retrieved using countChildren.
Elements Containing Character Data
If an elements contains character data, like in the following example:
    <title>The Title</title>
you can retrieve that data using the method getContent.
Subclassing XMLElement
When subclassing XMLElement, you need to override the method createAnotherElement which has to return a new copy of the receiver.

Author:
Marc De Scheemaecker <cyberelf@mac.com>
See Also:
  • Field Details

    • NANOXML_MAJOR_VERSION

      public static final int NANOXML_MAJOR_VERSION
      Major version of NanoXML. Classes with the same major and minor version are binary compatible. Classes with the same major version are source compatible. If the major version is different, you may need to modify the client source code.
      See Also:
    • NANOXML_MINOR_VERSION

      public static final int NANOXML_MINOR_VERSION
      Minor version of NanoXML. Classes with the same major and minor version are binary compatible. Classes with the same major version are source compatible. If the major version is different, you may need to modify the client source code.
      See Also:
  • Constructor Details

    • XMLElement

      public XMLElement()
      Creates and initializes a new XML element. Calling the construction is equivalent to:
        new XMLElement(new Hashtable(), false, true)
      Postconditions:
      • countChildren() => 0
      • enumerateChildren() => empty enumeration
      • enumeratePropertyNames() => empty enumeration
      • getChildren() => empty vector
      • getContent() => ""
      • getLineNr() => 0
      • getName() => null
      See Also:
    • XMLElement

      public XMLElement(Hashtable entities)
      Creates and initializes a new XML element. Calling the construction is equivalent to:
        new XMLElement(entities, false, true)
      Parameters:
      entities - The entity conversion table.
      Preconditions:
      • entities != null
      Postconditions:
      • countChildren() => 0
      • enumerateChildren() => empty enumeration
      • enumeratePropertyNames() => empty enumeration
      • getChildren() => empty vector
      • getContent() => ""
      • getLineNr() => 0
      • getName() => null
      See Also:
    • XMLElement

      public XMLElement(boolean skipLeadingWhitespace)
      Creates and initializes a new XML element. Calling the construction is equivalent to:
        new XMLElement(new Hashtable(), skipLeadingWhitespace, true)
      Parameters:
      skipLeadingWhitespace - true if leading and trailing whitespace in PCDATA content has to be removed.
      Postconditions:
      • countChildren() => 0
      • enumerateChildren() => empty enumeration
      • enumeratePropertyNames() => empty enumeration
      • getChildren() => empty vector
      • getContent() => ""
      • getLineNr() => 0
      • getName() => null
      See Also:
    • XMLElement

      public XMLElement(Hashtable entities, boolean skipLeadingWhitespace)
      Creates and initializes a new XML element. Calling the construction is equivalent to:
        new XMLElement(entities, skipLeadingWhitespace, true)
      Parameters:
      entities - The entity conversion table.
      skipLeadingWhitespace - true if leading and trailing whitespace in PCDATA content has to be removed.
      Preconditions:
      • entities != null
      Postconditions:
      • countChildren() => 0
      • enumerateChildren() => empty enumeration
      • enumeratePropertyNames() => empty enumeration
      • getChildren() => empty vector
      • getContent() => ""
      • getLineNr() => 0
      • getName() => null
      See Also:
    • XMLElement

      public XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase)
      Creates and initializes a new XML element.
      Parameters:
      entities - The entity conversion table.
      skipLeadingWhitespace - true if leading and trailing whitespace in PCDATA content has to be removed.
      ignoreCase - true if the case of element and attribute names have to be ignored.
      Preconditions:
      • entities != null
      Postconditions:
      • countChildren() => 0
      • enumerateChildren() => empty enumeration
      • enumeratePropertyNames() => empty enumeration
      • getChildren() => empty vector
      • getContent() => ""
      • getLineNr() => 0
      • getName() => null
      See Also:
    • XMLElement

      protected XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)
      Creates and initializes a new XML element.

      This constructor should only be called from createAnotherElement to create child elements.

      Parameters:
      entities - The entity conversion table.
      skipLeadingWhitespace - true if leading and trailing whitespace in PCDATA content has to be removed.
      fillBasicConversionTable - true if the basic entities need to be added to the entity list.
      ignoreCase - true if the case of element and attribute names have to be ignored.
      Preconditions:
      • entities != null
      • if fillBasicConversionTable == false then entities contains at least the following entries: amp, lt, gt, apos and quot
      Postconditions:
      • countChildren() => 0
      • enumerateChildren() => empty enumeration
      • enumeratePropertyNames() => empty enumeration
      • getChildren() => empty vector
      • getContent() => ""
      • getLineNr() => 0
      • getName() => null
      See Also:
  • Method Details