This is the only package in the NanoXML library. This version has only two classes: XMLElement and XMLParseException. XMLElement represents an XML document and its content. XMLParseException is the exception that is thrown when a parse error occurs; for example, when a document that is not well-formed is encountered. Let's look at each of these classes in detail.
Class XMLElement
nanoxml
public class XMLElement
XMLElement is a representation of an XML document. In addition to being able to parse XML documents, this serializable class contains all the methods needed to get/set elements, subelements, attributes, and text in a document. It derives from java.lang.Object.
Constructors
public XMLElement()
public XMLElement(Properties conversionTable)
public XMLElement(boolean skipLeadingWhitespace)
public XMLElement(Properties conversionTable,
boolean skipLeadingWhitespace)
public XMLElement(Properties conversionTable,
boolean skipLeadingWhitespace,
boolean ignoreCase)
Arguments
The XMLElement constructor can only take a few different arguments. Each constructor makes use of a conversion table. A conversion table is simply a Properties object, which is used to map entities to their conversion values. When an entity is found in a parsed document, it is used as a key into the Properties object to find the replacement value.
The default constructor creates a new XMLElement object with a Properties map that converts the following predefined entities:
Here is a summary of the constructor arguments:
Arguments
Type
Effect
conversionTable
java.util.Properties
Entities are keys
into the Properties
map that provide a replacement value when the key is found in during parsing
SkipLeadingWhitespace
boolean
Directs the parser
to ignore leading whitespace in #PCDATA
ignoreCase
boolean
Directs the parser
to ignore element and attribute case. Useful for HTML parsing.
If a conversion table is specified, the base entities specified above (& < > ' ") are used in addition to that table. The default values for the other two arguments are false for skipLeadingWhitespace (whitespace won't be skipped), and notice that the default argument is true for ignoreCase.
Parse Methods
The parse() methods direct an XMLElement object to begin parsing an XML document.
public void parseString (String string)
throws XMLParseException
public int parseString (String string, int offset)
throws XMLParseException
public int parseString (String string, int offset, int end)
throws XMLParseException
public int parseString (String string, int offset,
int end, int startingLineNr)
throws XMLParseException
public void parseFromReader(java.io.Reader reader)
throws IOException, XMLParseException
public void parseFromReader(java.io.Reader reader, int startingLineNr)
throws IOException, XMLParseException
public int parseCharArray (char[]chrAry, int offset, int end)
throws XMLParseException
public int parseCharArray(char[] chrAry, int offset, int end,
int startingLineNr)
throws XMLParseException
The parseString() and parseFromReader() methods actually just resolve to one of the parseFromCharArray() method calls.
Arguments
Type
Effect
string
String
XML source content
is contained within a string
reader
java.io.
Reader
XML source content
is contained within a java.io.Reader
chrAry
char[]
XML source content
is contained within a character array
offset
int
Marks where parsing should begin, counting from the first character
End
int
Marks where parsing
should end
startingLineNr
int
Marks from which
line the parser should begin parsing
Usage and Examples
To direct NanoXML to parse an XML file, we would write code like this:
REPORTS
Analyize In-Line NAC strategies and products.
ANALYTICS Plan and design your enterprise blade server deployments
InformationWeek U.S. IT Salary Survey 2008
Salaries for business technology professionals are falling. Here's what you need to know in order to make good hiring decisions and personal career choices. Download Today