|
IcedTea-Web NetX |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.nanoxml.XMLElement
public class XMLElement
XMLElement is a representation of an XML object. The object is able to parse XML code.
XMLElement xml = new XMLElement();
FileReader reader = new FileReader("filename.xml");
xml.parseFromReader(reader);
enumerateAttributeNames
.
The attribute values can be retrieved using the method
getAttribute
.
The following example shows how to list the attributes of an element:
XMLElement element = ...;
Enumeration enum = element.enumerateAttributeNames();
while (enum.hasMoreElements()) {
String key = (String) enum.nextElement();
String value = (String) element.getAttribute(key);
System.out.println(key + " = " + value);
}
enumerateChildren
.
The number of child elements can be retrieved using
countChildren
.
<title>The Title</title>
getContent
.
createAnotherElement
which has to return a new copy of the receiver.
XMLParseException
Constructor Summary | |
---|---|
|
XMLElement()
Creates and initializes a new XML element. |
protected |
XMLElement(java.util.Hashtable<java.lang.String,char[]> entities,
boolean skipLeadingWhitespace,
boolean fillBasicConversionTable,
boolean ignoreCase)
Creates and initializes a new XML element. |
Method Summary | |
---|---|
void |
addChild(XMLElement child)
Adds a child element. |
protected boolean |
checkCDATA(java.lang.StringBuffer buf)
Scans a special tag and if the tag is a CDATA section, append its content to buf . |
protected boolean |
checkLiteral(java.lang.String literal)
Scans the data for literal text. |
int |
countChildren()
Returns the number of child elements of the element. |
protected XMLElement |
createAnotherElement()
Creates a new similar XML element. |
java.util.Enumeration |
enumerateAttributeNames()
Enumerates the attribute names. |
java.util.Enumeration |
enumerateChildren()
Enumerates the child elements. |
protected XMLParseException |
expectedInput(java.lang.String charSet)
Creates a parse exception for when the next character read is not the character that was expected. |
protected XMLParseException |
expectedInput(java.lang.String charSet,
char ch)
Creates a parse exception for when the next character read is not the character that was expected. |
java.lang.Object |
getAttribute(java.lang.String name)
Returns an attribute of the element. |
java.lang.String |
getContent()
Returns the PCDATA content of the object. |
int |
getLineNr()
Returns the line nr in the source data on which the element is found. |
java.lang.String |
getName()
Returns the name of the element. |
protected XMLParseException |
invalidValue(java.lang.String name,
java.lang.String value)
Creates a parse exception for when an invalid value is given to a method. |
protected XMLParseException |
invalidValueSet(java.lang.String name)
Creates a parse exception for when an invalid valueset is given to a method. |
void |
parseFromReader(java.io.Reader reader)
Reads one XML element from a java.io.Reader and parses it. |
void |
parseFromReader(java.io.Reader reader,
int startingLineNr)
Reads one XML element from a java.io.Reader and parses it. |
protected char |
readChar()
Reads a character from a reader. |
protected void |
resolveEntity(java.lang.StringBuffer buf)
Resolves an entity. |
void |
sanitizeInput(java.io.InputStreamReader isr,
java.io.PipedOutputStream pout)
Reads an xml file and removes the comments, leaving only relevant xml code. |
protected void |
scanElement(XMLElement elt)
Scans an XML element. |
protected void |
scanIdentifier(java.lang.StringBuffer result)
Scans an identifier from the current reader. |
protected void |
scanPCData(java.lang.StringBuffer data)
Scans a #PCDATA element. |
protected void |
scanString(java.lang.StringBuffer string)
This method scans a delimited string from the current reader. |
protected char |
scanWhitespace()
This method scans an identifier from the current reader. |
protected char |
scanWhitespace(java.lang.StringBuffer result)
This method scans an identifier from the current reader. |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Adds or modifies an attribute. |
void |
setContent(java.lang.String content)
Changes the content string. |
void |
setName(java.lang.String name)
Changes the name of the element. |
protected void |
skipComment()
Skips a comment. |
protected void |
skipSpecialTag(int bracketLevel)
Skips a special tag or comment. |
protected XMLParseException |
syntaxError(java.lang.String context)
Creates a parse exception for when a syntax error occured. |
protected XMLParseException |
unexpectedEndOfData()
Creates a parse exception for when the end of the data input has been reached. |
protected XMLParseException |
unknownEntity(java.lang.String name)
Creates a parse exception for when an entity could not be resolved. |
protected void |
unreadChar(char ch)
Pushes a character back to the read-back buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public XMLElement()
new XMLElement(new Hashtable(), false, true)
protected XMLElement(java.util.Hashtable<java.lang.String,char[]> entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase)
This constructor should only be called from
createAnotherElement
to create child elements.
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 (client code calling this constructor).ignoreCase
- true
if the case of element and attribute names have
to be ignored.
entities != null
fillBasicConversionTable == false
then entities
contains at least the following
entries: amp
, lt
, gt
,
apos
and quot
Method Detail |
---|
public void addChild(XMLElement child)
child
- The child element to add.
child != null
child.getName() != null
child
does not have a parent element
public void setAttribute(java.lang.String name, java.lang.Object value)
name
- The name of the attribute.value
- The value of the attribute.
name != null
name
is a valid XML identifier
value != null
public int countChildren()
result >= 0
public java.util.Enumeration enumerateAttributeNames()
result != null
public java.util.Enumeration enumerateChildren()
result != null
public java.lang.String getContent()
null
is returned.
public int getLineNr()
0
there is no associated source data.
result >= 0
public java.lang.Object getAttribute(java.lang.String name)
null
is returned.
name
- The name of the attribute.
name != null
name
is a valid XML identifier
public java.lang.String getName()
public void parseFromReader(java.io.Reader reader) throws java.io.IOException, XMLParseException
reader
- The reader from which to retrieve the XML data.
reader != null
reader
is not closed
java.io.IOException
- If an error occured while reading the input.
XMLParseException
- If an error occured while parsing the read data.public void parseFromReader(java.io.Reader reader, int startingLineNr) throws java.io.IOException, XMLParseException
reader
- The reader from which to retrieve the XML data.startingLineNr
- The line number of the first line in the data.
reader != null
reader
is not closed
java.io.IOException
- If an error occured while reading the input.
XMLParseException
- If an error occured while parsing the read data.protected XMLElement createAnotherElement()
You should override this method when subclassing XMLElement.
public void setContent(java.lang.String content)
content
- The new content string.public void setName(java.lang.String name)
name
- The new name.
name != null
name
is a valid XML identifier
protected void scanIdentifier(java.lang.StringBuffer result) throws java.io.IOException
result
.
result
- The buffer in which the scanned identifier will be put.
result != null
java.io.IOException
protected char scanWhitespace() throws java.io.IOException
java.io.IOException
protected char scanWhitespace(java.lang.StringBuffer result) throws java.io.IOException
result
.
result != null
java.io.IOException
protected void scanString(java.lang.StringBuffer string) throws java.io.IOException
string
.
string != null
java.io.IOException
protected void scanPCData(java.lang.StringBuffer data) throws java.io.IOException
data
.
data != null
java.io.IOException
protected boolean checkCDATA(java.lang.StringBuffer buf) throws java.io.IOException
buf
.
buf != null
java.io.IOException
protected void skipComment() throws java.io.IOException
java.io.IOException
protected void skipSpecialTag(int bracketLevel) throws java.io.IOException
bracketLevel
- The number of open square brackets ([) that have
already been read.
bracketLevel >= 0
java.io.IOException
protected boolean checkLiteral(java.lang.String literal) throws java.io.IOException
literal
- the literal to check.
literal != null
java.io.IOException
protected char readChar() throws java.io.IOException
java.io.IOException
protected void scanElement(XMLElement elt) throws java.io.IOException
elt
- The element that will contain the result.
elt != null
java.io.IOException
protected void resolveEntity(java.lang.StringBuffer buf) throws java.io.IOException
buf
.
buf
- Where to put the entity value.
buf != null
java.io.IOException
protected void unreadChar(char ch)
ch
- The character to push back.
ch != '\0'
protected XMLParseException invalidValueSet(java.lang.String name)
name
- The name of the entity.
name != null
protected XMLParseException invalidValue(java.lang.String name, java.lang.String value)
name
- The name of the entity.value
- The value of the entity.
name != null
value != null
protected XMLParseException unexpectedEndOfData()
protected XMLParseException syntaxError(java.lang.String context)
context
- The context in which the error occured.
context != null
context.length() > 0
protected XMLParseException expectedInput(java.lang.String charSet)
charSet
- The set of characters (in human readable form) that was
expected.
charSet != null
charSet.length() > 0
protected XMLParseException expectedInput(java.lang.String charSet, char ch)
charSet
- The set of characters (in human readable form) that was
expected.ch
- The character that was received instead.
charSet != null
charSet.length() > 0
protected XMLParseException unknownEntity(java.lang.String name)
name
- The name of the entity.
name != null
name.length() > 0
public void sanitizeInput(java.io.InputStreamReader isr, java.io.PipedOutputStream pout)
isr
- The reader of the InputStream containing the xml.pout
- The PipedOutputStream that will be receiving the filtered
xml file.
|
IcedTea-Web NetX |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |