|
|||||||||
| Home >> All >> [ nanoxml overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
nanoxml
Class kXMLElement

java.lang.Objectnanoxml.kXMLElement
- public class kXMLElement
- extends java.lang.Object
kXMLElement is a representation of an XML object. The object is able to parse XML code.
Note that NanoXML is not 100% XML 1.0 compliant:
- The parser is non-validating.
- The DTD is fully ignored, including
<!ENTITY...>. - There is no support for mixed content (elements containing both subelements and CDATA elements)
You can opt to use a SAX compatible API, by including both nanoxml.jar
and nanoxml-sax.jar in your classpath and setting the property
org.xml.sax.parser to nanoxml.sax.SAXParser
$Revision: 1.2 $
$Date: 2002/06/05 01:27:16 $
- Version:
- 1.6
| Field Summary | |
private java.util.Hashtable |
attributes
The attributes given to the object. |
private java.util.Vector |
children
Subobjects of the object. |
private java.lang.String |
contents
The #PCDATA content of the object. |
private java.util.Hashtable |
conversionTable
Conversion table for &...; tags. |
private boolean |
ignoreCase
Whether the parsing is case sensitive. |
private int |
lineNr
The line number where the element starts. |
static int |
NANOXML_MAJOR_VERSION
Major version of NanoXML. |
static int |
NANOXML_MINOR_VERSION
Minor version of NanoXML. |
private kXMLElement |
parent
Parent of the object. |
private boolean |
skipLeadingWhitespace
Whether to skip leading whitespace in CDATA. |
private java.lang.String |
tagName
The class of the object (the name indicated in the tag). |
| Constructor Summary | |
|
kXMLElement()
Creates a new XML element. |
|
kXMLElement(boolean skipLeadingWhitespace)
Creates a new XML element. |
|
kXMLElement(java.util.Hashtable conversionTable)
Creates a new XML element. |
|
kXMLElement(java.util.Hashtable conversionTable,
boolean skipLeadingWhitespace)
Creates a new XML element. |
|
kXMLElement(java.util.Hashtable conversionTable,
boolean skipLeadingWhitespace,
boolean ignoreCase)
Creates a new XML element. |
protected |
kXMLElement(java.util.Hashtable conversionTable,
boolean skipLeadingWhitespace,
boolean fillBasicConversionTable,
boolean ignoreCase)
Creates a new XML element. |
| Method Summary | |
void |
addChild(kXMLElement child)
Adds a subobject. |
void |
addProperty(java.lang.String key,
int value)
Adds a property. |
void |
addProperty(java.lang.String key,
java.lang.Object value)
Adds a property. |
int |
countChildren()
Returns the number of subobjects of the object. |
protected kXMLElement |
createAnotherElement()
Creates a new XML element. |
protected java.lang.String |
decodeString(java.lang.String s,
int lineNr)
Converts &...; sequences to "normal" chars. |
java.util.Enumeration |
enumerateChildren()
Enumerates the subobjects of the object. |
java.util.Enumeration |
enumeratePropertyNames()
Enumerates the attribute names. |
private kXMLParseException |
expectedInput(java.lang.String charSet,
int lineNr)
A character has been expected. |
private java.util.Hashtable |
getAttributes()
Gets the attributes attribute of the kXMLElement object |
java.util.Vector |
getChildren()
Returns the subobjects of the object. |
java.lang.String |
getContents()
Returns the #PCDATA content of the object. |
int |
getIntProperty(java.lang.String key,
java.util.Hashtable valueSet,
java.lang.String defaultValue)
Returns a property by looking up a key in a hashtable. |
int |
getLineNr()
Returns the line nr on which the element is found. |
kXMLElement |
getParent()
Gets its parent. |
static java.lang.String |
getProperty(java.util.Hashtable h,
java.lang.String key)
|
static java.lang.String |
getProperty(java.util.Hashtable h,
java.lang.String key,
java.lang.String def)
|
java.lang.String |
getProperty(java.lang.String key)
Returns a property of the object. |
java.lang.Object |
getProperty(java.lang.String key,
java.util.Hashtable valueSet,
java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet If the property doesn't exist, the value corresponding to defaultValue is returned. |
int |
getProperty(java.lang.String key,
int defaultValue)
Returns an integer property of the object. |
java.lang.String |
getProperty(java.lang.String key,
java.lang.String defaultValue)
Returns a property of the object. |
boolean |
getProperty(java.lang.String key,
java.lang.String trueValue,
java.lang.String falseValue,
boolean defaultValue)
Returns a boolean property of the object. |
int |
getSpecialIntProperty(java.lang.String key,
java.util.Hashtable valueSet,
java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet . |
java.lang.String |
getStringProperty(java.lang.String key,
java.util.Hashtable valueSet,
java.lang.String defaultValue)
Returns a property by looking up a key in the hashtable valueSet . |
java.lang.String |
getTagName()
Returns the class (i.e. |
private kXMLParseException |
invalidValue(java.lang.String key,
java.lang.String value,
int lineNr)
Creates a parse exception for when an invalid value is given to a method. |
private kXMLParseException |
invalidValueSet(java.lang.String key)
Creates a parse exception for when an invalid valueset is given to a method. |
private boolean |
isIdentifierChar(char ch)
Checks whether a character may be part of an identifier. |
int |
parseCharArray(char[] input,
int offset,
int end)
Parses an XML definition starting at offset . |
int |
parseCharArray(char[] input,
int offset,
int end,
int startingLineNr)
Parses an XML definition starting at offset . |
private int |
parseCharArray(char[] input,
int offset,
int end,
int[] currentLineNr)
Parses an XML definition starting at offset . |
void |
parseFromReader(java.io.Reader reader)
Reads an XML definition from a java.io.Reader and parses it. |
void |
parseFromReader(java.io.Reader reader,
int startingLineNr)
Reads an XML definition from a java.io.Reader and parses it. |
void |
parseString(java.lang.String string)
Parses an XML definition. |
int |
parseString(java.lang.String string,
int offset)
Parses an XML definition starting at offset . |
int |
parseString(java.lang.String string,
int offset,
int end)
Parses an XML definition starting at offset . |
int |
parseString(java.lang.String string,
int offset,
int end,
int startingLineNr)
Parses an XML definition starting at offset . |
private void |
processContents(char[] input,
int contentOffset,
int contentSize,
int contentLineNr)
Decodes the entities in the contents and, if skipLeadingWhitespace is true, removes extraneous whitespaces after newlines and
convert those newlines into spaces. |
void |
removeChild(kXMLElement child)
Removes a child object. |
void |
removeChild(java.lang.String key)
Removes an attribute. |
private int |
scanAttributes(char[] input,
int offset,
int end,
int[] lineNr)
Scans the attributes of the object. |
protected void |
scanChildren(char[] input,
int contentOffset,
int contentSize,
int contentLineNr)
!!! Searches the content for child objects. |
private int |
scanContent(char[] input,
int offset,
int end,
int[] contentOffset,
int[] contentSize,
int[] lineNr)
Scans the content of the object. |
private java.lang.String |
scanIdentifier(char[] input,
int offset,
int end)
Scans an identifier. |
private int |
scanOneAttribute(char[] input,
int offset,
int end,
int[] lineNr)
Scans one attribute of an object. |
private java.lang.String |
scanString(char[] input,
int offset,
int end,
int[] lineNr)
Scans a string. |
private int |
scanTagName(char[] input,
int offset,
int end,
int[] lineNr)
Scans the class (tag) name of the object. |
void |
setContent(java.lang.String content)
Changes the content string. |
private void |
setParent(kXMLElement parent)
Sets the parent of this instance. |
void |
setTagName(java.lang.String tagName)
Changes the tag name. |
protected int |
skipBogusTag(char[] input,
int offset,
int end,
int[] lineNr)
Skips a tag that don't contain any useful data: <?...?>, <!...> and comments. |
private int |
skipPreamble(char[] input,
int offset,
int end,
int[] lineNr)
Skips a tag that don't contain any useful data: <?...?>, <!...> and comments. |
private int |
skipWhitespace(char[] input,
int offset,
int end,
int[] lineNr)
Skips whitespace characters. |
private kXMLParseException |
syntaxError(java.lang.String context,
int lineNr)
A syntax error occured. |
java.lang.String |
toString()
Writes the XML element to a string. |
private kXMLParseException |
unexpectedEndOfData(int lineNr)
The end of the data input has been reached. |
private kXMLParseException |
valueMissingForAttribute(java.lang.String key,
int lineNr)
A value is missing for an attribute. |
void |
write(java.io.Writer writer)
Writes the XML element to a writer. |
void |
write(java.io.Writer writer,
int indent)
Writes the XML element to a writer. |
protected void |
writeEncoded(kXMLPrintWriter out,
java.lang.String str)
Writes a string encoded to a writer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
NANOXML_MAJOR_VERSION
public static final int NANOXML_MAJOR_VERSION
- Major version of NanoXML.
- See Also:
- Constant Field Values
NANOXML_MINOR_VERSION
public static final int NANOXML_MINOR_VERSION
- Minor version of NanoXML.
- See Also:
- Constant Field Values
attributes
private java.util.Hashtable attributes
- The attributes given to the object.
parent
private kXMLElement parent
- Parent of the object.
children
private java.util.Vector children
- Subobjects of the object. The subobjects are of class kXMLElement
themselves.
tagName
private java.lang.String tagName
- The class of the object (the name indicated in the tag).
contents
private java.lang.String contents
- The #PCDATA content of the object. If there is no such content, this
field is null.
conversionTable
private java.util.Hashtable conversionTable
- Conversion table for &...; tags.
skipLeadingWhitespace
private boolean skipLeadingWhitespace
- Whether to skip leading whitespace in CDATA.
lineNr
private int lineNr
- The line number where the element starts.
ignoreCase
private boolean ignoreCase
- Whether the parsing is case sensitive.
| Constructor Detail |
kXMLElement
public kXMLElement()
- Creates a new XML element. The following settings are used:
- Conversion table
- Minimal XML conversions:
& < > ' " - Skip whitespace in contents
-
false - Ignore Case
-
true
kXMLElement
public kXMLElement(java.util.Hashtable conversionTable)
- Creates a new XML element. The following settings are used:
- Conversion table
- conversionTable combined with the minimal XML
conversions:
& < > ' " - Skip whitespace in contents
-
false - Ignore Case
-
true
kXMLElement
public kXMLElement(boolean skipLeadingWhitespace)
- Creates a new XML element. The following settings are used:
- Conversion table
- Minimal XML conversions:
& < > ' " - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
-
true
kXMLElement
public kXMLElement(java.util.Hashtable conversionTable, boolean skipLeadingWhitespace)
- Creates a new XML element. The following settings are used:
- Conversion table
- conversionTable combined with the minimal XML
conversions:
& < > ' " - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
-
true
kXMLElement
public kXMLElement(java.util.Hashtable conversionTable, boolean skipLeadingWhitespace, boolean ignoreCase)
- Creates a new XML element. The following settings are used:
- Conversion table
- conversionTable , eventually combined with the minimal
XML conversions:
& < > ' "(depending on fillBasicConversionTable ) - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
- ignoreCase
This constructor should only be called from kXMLElement itself to create child elements.
kXMLElement
protected kXMLElement(java.util.Hashtable conversionTable, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)
- Creates a new XML element. The following settings are used:
- Conversion table
- conversionTable , eventually combined with the minimal
XML conversions:
& < > ' "(depending on fillBasicConversionTable ) - Skip whitespace in contents
- skipLeadingWhitespace
- Ignore Case
- ignoreCase
This constructor should only be called from kXMLElement itself to create child elements.
| Method Detail |
getParent
public kXMLElement getParent()
- Gets its parent.
setParent
private void setParent(kXMLElement parent)
- Sets the parent of this instance.
addChild
public void addChild(kXMLElement child)
- Adds a subobject.
getAttributes
private java.util.Hashtable getAttributes()
- Gets the attributes attribute of the kXMLElement object
addProperty
public void addProperty(java.lang.String key, java.lang.Object value)
- Adds a property. If the element is case insensitive, the property name
is capitalized.
addProperty
public void addProperty(java.lang.String key, int value)
- Adds a property. If the element is case insensitive, the property name
is capitalized.
countChildren
public int countChildren()
- Returns the number of subobjects of the object.
enumeratePropertyNames
public java.util.Enumeration enumeratePropertyNames()
- Enumerates the attribute names.
enumerateChildren
public java.util.Enumeration enumerateChildren()
- Enumerates the subobjects of the object.
getChildren
public java.util.Vector getChildren()
- Returns the subobjects of the object.
getContents
public java.lang.String getContents()
- Returns the #PCDATA content of the object. If there is no such content,
nullis returned.
getLineNr
public int getLineNr()
- Returns the line nr on which the element is found.
getIntProperty
public int getIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
- Returns a property by looking up a key in a hashtable. If the property
doesn't exist, the value corresponding to defaultValue is returned.
getProperty
public static java.lang.String getProperty(java.util.Hashtable h, java.lang.String key)
getProperty
public static java.lang.String getProperty(java.util.Hashtable h, java.lang.String key, java.lang.String def)
getProperty
public java.lang.String getProperty(java.lang.String key)
- Returns a property of the object. If there is no such property, this
method returns
null.
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)
- Returns a property of the object. If the property doesn't exist,
defaultValue is returned.
getProperty
public int getProperty(java.lang.String key, int defaultValue)
- Returns an integer property of the object. If the property doesn't
exist, defaultValue is returned.
getProperty
public boolean getProperty(java.lang.String key, java.lang.String trueValue, java.lang.String falseValue, boolean defaultValue)
- Returns a boolean property of the object. If the property is missing,
defaultValue is returned.
getProperty
public java.lang.Object getProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
- Returns a property by looking up a key in the hashtable valueSet
If the property doesn't exist, the value corresponding to
defaultValue is returned.
getStringProperty
public java.lang.String getStringProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
- Returns a property by looking up a key in the hashtable valueSet
. If the property doesn't exist, the value corresponding to
defaultValue is returned.
getSpecialIntProperty
public int getSpecialIntProperty(java.lang.String key, java.util.Hashtable valueSet, java.lang.String defaultValue)
- Returns a property by looking up a key in the hashtable valueSet
. If the value is not defined in the hashtable, the value is considered
to be an integer. If the property doesn't exist, the value
corresponding to defaultValue is returned.
getTagName
public java.lang.String getTagName()
- Returns the class (i.e. the name indicated in the tag) of the object.
isIdentifierChar
private boolean isIdentifierChar(char ch)
- Checks whether a character may be part of an identifier.
parseFromReader
public void parseFromReader(java.io.Reader reader) throws java.io.IOException, kXMLParseException
- Reads an XML definition from a java.io.Reader and parses it.
parseFromReader
public void parseFromReader(java.io.Reader reader, int startingLineNr) throws java.io.IOException, kXMLParseException
- Reads an XML definition from a java.io.Reader and parses it.
parseString
public void parseString(java.lang.String string) throws kXMLParseException
- Parses an XML definition.
parseString
public int parseString(java.lang.String string, int offset) throws kXMLParseException
- Parses an XML definition starting at offset .
parseString
public int parseString(java.lang.String string, int offset, int end) throws kXMLParseException
- Parses an XML definition starting at offset .
parseString
public int parseString(java.lang.String string, int offset, int end, int startingLineNr) throws kXMLParseException
- Parses an XML definition starting at offset .
parseCharArray
public int parseCharArray(char[] input,
int offset,
int end)
throws kXMLParseException
- Parses an XML definition starting at offset .
parseCharArray
public int parseCharArray(char[] input,
int offset,
int end,
int startingLineNr)
throws kXMLParseException
- Parses an XML definition starting at offset .
parseCharArray
private int parseCharArray(char[] input,
int offset,
int end,
int[] currentLineNr)
throws kXMLParseException
- Parses an XML definition starting at offset .
processContents
private void processContents(char[] input,
int contentOffset,
int contentSize,
int contentLineNr)
throws kXMLParseException
- Decodes the entities in the contents and, if skipLeadingWhitespace is
true, removes extraneous whitespaces after newlines and convert those newlines into spaces.
removeChild
public void removeChild(kXMLElement child)
- Removes a child object. If the object is not a child, nothing happens.
removeChild
public void removeChild(java.lang.String key)
- Removes an attribute.
scanAttributes
private int scanAttributes(char[] input,
int offset,
int end,
int[] lineNr)
throws kXMLParseException
- Scans the attributes of the object.
scanChildren
protected void scanChildren(char[] input,
int contentOffset,
int contentSize,
int contentLineNr)
throws kXMLParseException
- !!! Searches the content for child objects. If such objects exist, the
content is reduced to
null.
createAnotherElement
protected kXMLElement createAnotherElement()
- Creates a new XML element.
scanContent
private int scanContent(char[] input,
int offset,
int end,
int[] contentOffset,
int[] contentSize,
int[] lineNr)
throws kXMLParseException
- Scans the content of the object.
scanIdentifier
private java.lang.String scanIdentifier(char[] input, int offset, int end)
- Scans an identifier.
scanOneAttribute
private int scanOneAttribute(char[] input,
int offset,
int end,
int[] lineNr)
throws kXMLParseException
- Scans one attribute of an object.
scanString
private java.lang.String scanString(char[] input, int offset, int end, int[] lineNr) throws kXMLParseException
- Scans a string. Strings are either identifiers, or text delimited by
double quotes.
scanTagName
private int scanTagName(char[] input,
int offset,
int end,
int[] lineNr)
throws kXMLParseException
- Scans the class (tag) name of the object.
setContent
public void setContent(java.lang.String content)
- Changes the content string.
setTagName
public void setTagName(java.lang.String tagName)
- Changes the tag name.
skipBogusTag
protected int skipBogusTag(char[] input,
int offset,
int end,
int[] lineNr)
- Skips a tag that don't contain any useful data: <?...?>,
<!...> and comments.
skipPreamble
private int skipPreamble(char[] input,
int offset,
int end,
int[] lineNr)
throws kXMLParseException
- Skips a tag that don't contain any useful data: <?...?>,
<!...> and comments.
skipWhitespace
private int skipWhitespace(char[] input,
int offset,
int end,
int[] lineNr)
- Skips whitespace characters.
decodeString
protected java.lang.String decodeString(java.lang.String s, int lineNr)
- Converts &...; sequences to "normal" chars.
toString
public java.lang.String toString()
- Writes the XML element to a string.
write
public void write(java.io.Writer writer)
- Writes the XML element to a writer.
write
public void write(java.io.Writer writer, int indent)
- Writes the XML element to a writer.
writeEncoded
protected void writeEncoded(kXMLPrintWriter out, java.lang.String str)
- Writes a string encoded to a writer.
invalidValueSet
private kXMLParseException invalidValueSet(java.lang.String key)
- Creates a parse exception for when an invalid valueset is given to a
method.
invalidValue
private kXMLParseException invalidValue(java.lang.String key, java.lang.String value, int lineNr)
- Creates a parse exception for when an invalid value is given to a
method.
unexpectedEndOfData
private kXMLParseException unexpectedEndOfData(int lineNr)
- The end of the data input has been reached.
syntaxError
private kXMLParseException syntaxError(java.lang.String context, int lineNr)
- A syntax error occured.
expectedInput
private kXMLParseException expectedInput(java.lang.String charSet, int lineNr)
- A character has been expected.
valueMissingForAttribute
private kXMLParseException valueMissingForAttribute(java.lang.String key, int lineNr)
- A value is missing for an attribute.
|
|||||||||
| Home >> All >> [ nanoxml overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
nanoxml.kXMLElement