public class XElement extends XElementBase
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
attributes
The attribute map.
|
protected java.util.List<XElement> |
children
The child elements.
|
XElement |
parent
The parent element.
|
content, name, userObject, XSD, XSI| Constructor and Description |
|---|
XElement(java.lang.String name)
Constructor.
|
XElement(java.lang.String name,
java.lang.Object value)
Creates a new XElement and sets its content according to the supplied value.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.Iterable<XElement> elements)
Add the iterable of elements as children.
|
XElement |
add(java.lang.String name)
Add a new child element with the given name.
|
XElement |
add(java.lang.String name,
java.lang.Object value)
Add an element with the supplied content text.
|
void |
add(XElement... elements)
Add the array of elements as children.
|
void |
add(XElement element)
Add the array of elements as children.
|
java.util.Map<java.lang.String,java.lang.String> |
attributes() |
XElement |
childElement(java.lang.String name)
Returns the first child element with the given name.
|
java.util.List<XElement> |
children() |
java.lang.Iterable<XElement> |
childrenWithName(java.lang.String name)
Returns an iterator which enumerates all children with the given name.
|
java.lang.String |
childValue(java.lang.String name)
Returns the content of the first child which has the given name.
|
void |
clear()
Remove attributes and children.
|
XElement |
copy() |
void |
copyFrom(XElement other)
Copy the attributes, content and child elements from the other element
in a deep-copy fashion.
|
void |
detach()
Detach this element from its parent.
|
java.lang.String |
get(java.lang.String attributeName) |
java.lang.String |
get(java.lang.String attributeName,
java.lang.String def) |
boolean |
getBoolean(java.lang.String name) |
boolean |
getBoolean(java.lang.String name,
boolean defaultValue) |
byte |
getByte(java.lang.String key) |
byte |
getByte(java.lang.String key,
byte defaultValue) |
char |
getChar(java.lang.String key) |
char |
getChar(java.lang.String key,
char defaultValue) |
double |
getDouble(java.lang.String name) |
double |
getDouble(java.lang.String name,
double defaultValue) |
java.lang.Double |
getDoubleObject(java.lang.String attributeName)
Get a double attribute as object or null if not present.
|
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String name,
java.lang.Class<E> clazz) |
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String name,
java.lang.Class<E> clazz,
E defaultValue) |
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String key,
E[] universe) |
<E extends java.lang.Enum<E>> |
getEnum(java.lang.String key,
E[] universe,
E defaultValue) |
float |
getFloat(java.lang.String attributeName) |
float |
getFloat(java.lang.String key,
float defaultValue) |
int |
getInt(java.lang.String attributeName) |
int |
getInt(java.lang.String attributeName,
int def) |
java.lang.Integer |
getIntObject(java.lang.String attributeName)
Get an integer attribute as object or null if not present.
|
long |
getLong(java.lang.String attributeName) |
long |
getLong(java.lang.String attributeName,
long def) |
short |
getShort(java.lang.String key) |
short |
getShort(java.lang.String key,
short defaultValue) |
boolean |
has(java.lang.String attributeName) |
boolean |
hasChildren() |
boolean |
hasDouble(java.lang.String attributeName)
Check if there is a valid integer attribute.
|
boolean |
hasFloat(java.lang.String attributeName)
Check if there is a valid integer attribute.
|
boolean |
hasInt(java.lang.String attributeName)
Check if there is a valid integer attribute.
|
boolean |
hasLong(java.lang.String attributeName)
Check if there is a valid integer attribute.
|
boolean |
hasPositiveInt(java.lang.String attributeName)
Check if there is a valid positive integer attribute.
|
boolean |
isNullOrEmpty(java.lang.String attributeName)
Check if the given attribute is present an is not empty.
|
static XElement |
parseXML(byte[] data)
Parse an XML from the binary data.
|
static XElement |
parseXML(java.io.File file)
Parse an XML from the given local file.
|
static XElement |
parseXML(java.io.InputStream in)
Parse an XML document from the given input stream.
|
static XElement |
parseXML(java.io.Reader in)
Parse an XML document from the given reader.
|
static XElement |
parseXML(java.sql.ResultSet rs,
int index)
Reads the contents of a indexed column as an XML.
|
static XElement |
parseXML(java.sql.ResultSet rs,
java.lang.String column)
Reads the contents of a named column as an XML.
|
static XElement |
parseXML(java.lang.String fileName)
Parse an XML from the given local filename.
|
static XElement |
parseXML(java.net.URL u)
Parses an XML from the given URL.
|
static XElement |
parseXML(javax.xml.stream.XMLStreamReader in)
Parse an XML from an XML stream reader.
|
static XElement |
parseXMLFragment(javax.xml.stream.XMLStreamReader in)
Parse an XML from an XML stream reader.
|
static XElement |
parseXMLGZ(java.io.File file)
Parse an XML file compressed by GZIP.
|
static XElement |
parseXMLGZ(java.lang.String fileName)
Parse an XML file compressed by GZIP.
|
void |
remove(XElement element)
Remove the given element from the children.
|
void |
removeChildrenWithName(java.lang.String name)
Removes all children with the given element name.
|
void |
replace(XElement oldChild,
XElement newChild)
Replaces the specified child node with the new node.
|
void |
save(java.io.File file)
Save this XML into the given file.
|
void |
save(java.io.OutputStream stream)
Save this XML into the supplied output stream.
|
void |
save(java.lang.String fileName)
Save this XML into the given file.
|
void |
save(java.io.Writer writer)
Save this XML into the supplied output writer.
|
void |
set(java.lang.String name,
java.lang.Object value)
Set an attribute value.
|
java.lang.String |
toString() |
void |
visit(boolean depthFirst,
java.util.function.Consumer<? super XElement> action)
Iterate through the elements of this XElement and invoke the action for each.
|
doubleValue, doubleValue, formatDateTime, formatDateTime, intValue, intValue, longValue, longValue, parseDateTime, sanitize, setValueprotected final java.util.Map<java.lang.String,java.lang.String> attributes
protected final java.util.List<XElement> children
public XElement parent
public XElement(java.lang.String name)
name - the element namepublic XElement(java.lang.String name,
java.lang.Object value)
name - the element namevalue - the content valuepublic static XElement parseXML(byte[] data) throws javax.xml.stream.XMLStreamException
data - the XML datajavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXML(java.io.File file) throws javax.xml.stream.XMLStreamException
file - the file objectjavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXML(java.io.InputStream in) throws javax.xml.stream.XMLStreamException
in - the input streamjavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXML(java.io.Reader in) throws javax.xml.stream.XMLStreamException
in - the InputStream objectjavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXML(java.sql.ResultSet rs, int index) throws java.sql.SQLException, java.io.IOException, javax.xml.stream.XMLStreamException
rs - the result set to read fromindex - the column indexjava.sql.SQLException - on SQL errorjava.io.IOException - on IO errorjavax.xml.stream.XMLStreamException - on parsing errorpublic static XElement parseXML(java.sql.ResultSet rs, java.lang.String column) throws java.sql.SQLException, java.io.IOException, javax.xml.stream.XMLStreamException
rs - the result set to read fromcolumn - the column namejava.sql.SQLException - on SQL errorjava.io.IOException - on IO errorjavax.xml.stream.XMLStreamException - on parsing errorpublic static XElement parseXML(java.lang.String fileName) throws javax.xml.stream.XMLStreamException
fileName - the file namejavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXML(java.net.URL u) throws javax.xml.stream.XMLStreamException, java.io.IOException
u - the urljavax.xml.stream.XMLStreamException - on errorjava.io.IOException - on errorpublic static XElement parseXML(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException
in - the XMLStreamReader objectjavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXMLFragment(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException
in - the XMLStreamReader objectjavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXMLGZ(java.io.File file) throws javax.xml.stream.XMLStreamException
file - the filejavax.xml.stream.XMLStreamException - on errorpublic static XElement parseXMLGZ(java.lang.String fileName) throws javax.xml.stream.XMLStreamException
fileName - the filenamejavax.xml.stream.XMLStreamException - on errorpublic void add(java.lang.Iterable<XElement> elements)
elements - the elements to addpublic XElement add(java.lang.String name)
name - the element namepublic XElement add(java.lang.String name, java.lang.Object value)
name - the namevalue - the contentpublic void add(XElement... elements)
elements - the elements to addpublic void add(XElement element)
element - the element to addpublic java.util.Map<java.lang.String,java.lang.String> attributes()
public XElement childElement(java.lang.String name)
name - the child namepublic java.util.List<XElement> children()
public java.lang.Iterable<XElement> childrenWithName(java.lang.String name)
name - the name of the children to selectpublic void clear()
public XElement copy()
copy in class XElementBasepublic void copyFrom(XElement other)
other - the other elementpublic void detach()
public java.lang.String get(java.lang.String attributeName)
public java.lang.String get(java.lang.String attributeName,
java.lang.String def)
public boolean getBoolean(java.lang.String name)
public boolean getBoolean(java.lang.String name,
boolean defaultValue)
public byte getByte(java.lang.String key)
public byte getByte(java.lang.String key,
byte defaultValue)
public char getChar(java.lang.String key)
public char getChar(java.lang.String key,
char defaultValue)
public double getDouble(java.lang.String name)
public double getDouble(java.lang.String name,
double defaultValue)
public java.lang.Double getDoubleObject(java.lang.String attributeName)
attributeName - the attribute namepublic <E extends java.lang.Enum<E>> E getEnum(java.lang.String name,
java.lang.Class<E> clazz)
public <E extends java.lang.Enum<E>> E getEnum(java.lang.String name,
java.lang.Class<E> clazz,
E defaultValue)
public <E extends java.lang.Enum<E>> E getEnum(java.lang.String key,
E[] universe)
public <E extends java.lang.Enum<E>> E getEnum(java.lang.String key,
E[] universe,
E defaultValue)
public float getFloat(java.lang.String attributeName)
public float getFloat(java.lang.String key,
float defaultValue)
public int getInt(java.lang.String attributeName)
public int getInt(java.lang.String attributeName,
int def)
public java.lang.Integer getIntObject(java.lang.String attributeName)
attributeName - the attribute namepublic long getLong(java.lang.String attributeName)
public long getLong(java.lang.String attributeName,
long def)
public short getShort(java.lang.String key)
public short getShort(java.lang.String key,
short defaultValue)
public boolean has(java.lang.String attributeName)
public boolean hasChildren()
public boolean hasDouble(java.lang.String attributeName)
attributeName - the attribute namepublic boolean hasFloat(java.lang.String attributeName)
attributeName - the attribute namepublic boolean hasInt(java.lang.String attributeName)
attributeName - the attribute namepublic boolean hasLong(java.lang.String attributeName)
attributeName - the attribute namepublic boolean hasPositiveInt(java.lang.String attributeName)
attributeName - the attribute namepublic boolean isNullOrEmpty(java.lang.String attributeName)
attributeName - the attribute namepublic void remove(XElement element)
element - the elementpublic void removeChildrenWithName(java.lang.String name)
name - the element namepublic void replace(XElement oldChild, XElement newChild)
oldChild - the old childnewChild - the new childpublic void save(java.io.File file)
throws java.io.IOException
file - the filejava.io.IOException - on errorpublic void save(java.io.OutputStream stream)
throws java.io.IOException
stream - the output streamjava.io.IOException - on errorpublic void save(java.lang.String fileName)
throws java.io.IOException
fileName - the file namejava.io.IOException - on errorpublic void save(java.io.Writer writer)
throws java.io.IOException
writer - the output writerjava.io.IOException - on errorpublic void set(java.lang.String name,
java.lang.Object value)
name - the attribute namevalue - the content value, null will remove any existingpublic java.lang.String toString()
toString in class java.lang.Objectpublic void visit(boolean depthFirst,
java.util.function.Consumer<? super XElement> action)
depthFirst - do a depth first search?action - the action to invoke, non-nullpublic java.lang.String childValue(java.lang.String name)
XElementBasechildValue in class XElementBasename - the child name