Class XmlElement
java.lang.Object
com.codename1.backend.xml.XmlElement
One element of a small in-memory XML tree, built by XmlPullParser.
XmlElement root = XmlElement.parse(bytes);
for (XmlElement item : root.children("item")) {
String id = item.getAttribute("id");
String title = item.child("title").getText();
}
The tree keeps elements, attributes and text; comments, processing instructions and the document type are dropped, exactly as the parser drops them. It carries every limit of the parser, including its refusal to expand any entity a document type declares, so it is safe for untrusted input.
-
Method Summary
Modifier and TypeMethodDescriptionThe first child element namedchildName, or null when there is none.Every child element namedchildName, in document order; empty when there is none.The text of the first child namedchildName, trimmed, or null when there is no such child.getAttribute(String attributeName) The decoded value of the named attribute, or null when there is none.Every attribute, in document order.The child elements in document order.getName()The element name as written, prefix included.getText()The element's own character data -- every text and CDATA run directly inside it, concatenated, with whitespace as written.static XmlElementparse(byte[] utf8) Parses a UTF-8 document and answers its root element.static XmlElementparse(XmlPullParser parser) Builds the tree from a parser positioned before the root element, reading it to the end of the document.static XmlElementparse(InputStream in) Readsinto its end as UTF-8 and answers the root element.static XmlElementParses a document held in a string and answers its root element.toString()Returns a string representation of the object.
-
Method Details
-
parse
Parses a UTF-8 document and answers its root element.
Throws
XmlException: when the document is not well formed; seeXmlPullParser.
- Throws:
XmlException
-
parse
Parses a document held in a string and answers its root element.
Throws
XmlException: when the document is not well formed; seeXmlPullParser.
- Throws:
XmlException
-
parse
Reads
into its end as UTF-8 and answers the root element. The stream is not closed.Throws
IOException: when reading fails, or anXmlExceptionwhen the document is not well formed.
- Throws:
IOException
-
parse
Builds the tree from a parser positioned before the root element, reading it to the end of the document. Configure the parser first, for example with
XmlPullParser.setMaxDepth(int).Throws
XmlException: when the document is not well formed.
- Throws:
XmlException
-
getName
The element name as written, prefix included. -
getAttribute
-
getAttributes
-
getChildren
The child elements in document order. The list is read-only. -
child
The first child element namedchildName, or null when there is none. -
children
Every child element namedchildName, in document order; empty when there is none. -
getText
The element's own character data -- every text and CDATA run directly inside it, concatenated, with whitespace as written. Text inside child elements is not included. -
childText
-
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-