|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.fractal.adl.XMLElement
An XML element. This class can also parse XML files, and can pretty print XML elements. It also offer some methods to help manually validate XML elements. But it does not handle XML entities, PCDATA and CDATA elements, XML DTDs, namespaces...
Field Summary | |
int |
line
The line number where this XML element starts. |
String |
source
The file from which this XML element was parsed. |
String |
tag
The tag of this XML element. |
Constructor Summary | |
XMLElement(String tag)
Creates a new empty XML element. |
|
XMLElement(XMLElement elem)
Creates a deep copy of the given XML element. |
Method Summary | |
void |
addSubElement(int index,
XMLElement subElement)
Adds a sub element to this XML element at the given index. |
void |
addSubElement(XMLElement subElement)
Adds a sub element to this XML element. |
void |
checkAttributes(String attrs)
Checks the attributes of this element. |
void |
checkSubElements(String subElements)
Checks the sub-elements of this element. |
String |
getAttribute(String key,
String defaultValue)
Returns an attribute of this XML element. |
String[] |
getAttributes()
Returns the names of the attributes of this XMLElement. |
XMLElement |
getSubElement(int index)
Returns the sub element of this XML element whose index is given. |
XMLElement |
getSubElement(String tag)
Returns the first sub element of this XML element whose tag is equal to the given tag. |
int |
getSubElementCount()
Returns the number of sub elements of this XML element. |
static XMLElement |
parse(LineNumberReader reader,
boolean parseComment)
Parses an XML element from a LineNumberReader . |
void |
removeSubElement(int index)
Removes the sub element of this XML element whose index is given. |
void |
setAttribute(String key,
String value)
Sets an attribute of this XML element. |
void |
write(Writer writer)
Writes the XML element to a writer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public String tag
public String source
public int line
Constructor Detail |
public XMLElement(String tag)
tag
- the tag of the element.public XMLElement(XMLElement elem)
elem
- the element to be cloned.Method Detail |
public final String[] getAttributes()
public final String getAttribute(String key, String defaultValue) throws ParserException
key
- the name of an attribute of this element.defaultValue
- the default value of this attribute, or null
if there is no default value.
ParserException
- if this element does not have such an attribute,
and the default value is null.setAttribute(String, String)
public final void setAttribute(String key, String value)
key
- the name of an attribute of this element.value
- the value of this attribute. May be null to remove
the attribute.getAttribute(String, String)
public final int getSubElementCount()
public final XMLElement getSubElement(int index)
index
- the index of a sub element of this XML element.
public final XMLElement getSubElement(String tag)
tag
- a tag name.
public final void addSubElement(XMLElement subElement)
subElement
- the sub element to be added to this XML element.public final void addSubElement(int index, XMLElement subElement)
index
- the index at which the given element must be added.subElement
- the sub element to be added to this XML element.public final void removeSubElement(int index)
index
- the index of a sub element to be removed.public void checkAttributes(String attrs) throws ParserException
attrs
- the name of the allowed attributes for this element, separated
by commas (for example "name,value,type").
ParserException
- if an attribute of this element is not specified
in the given allowed attributes list.public void checkSubElements(String subElements) throws ParserException
subElements
- the allowed sequences of sub element tags for this
element, given as a simplified regular expression: tag | tag* |
tag? | tag,tag. An example is "title,author,chapter*,annex?".
ParserException
- if the tags of the sub elements of this element do
not conform to the specified regular expression.public void write(Writer writer) throws IOException
writer
- the writer into which this element must be written.
IOException
- if an IO error occurs.public static XMLElement parse(LineNumberReader reader, boolean parseComment) throws IOException, ParserException
LineNumberReader
.
reader
- where to read the XML element.parseComment
- true to parse comments, or false to
skip them.
IOException
- if an IO error occurs.
ParserException
- if an XML syntax error is found.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |