public class XNElement extends XElementBase
| Modifier and Type | Class and Description |
|---|---|
static class |
XNElement.XAttributeName
The namespace:name record.
|
static class |
XNElement.XRepresentationRecord
The representation record.
|
static class |
XNElement.XRepresentationState
The representation state.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<XNElement.XAttributeName,java.lang.String> |
attributes
The attribute map.
|
protected java.util.List<XNElement> |
children
The child elements.
|
java.lang.String |
namespace
The optional associated namespace uri.
|
XNElement |
parent
The parent element.
|
java.lang.String |
prefix
The prefix used by this element.
|
content, name, userObject, XSD, XSI| Constructor and Description |
|---|
XNElement(java.lang.String name)
Constructor.
|
XNElement(java.lang.String name,
java.lang.Object value)
Creates a new XElement and sets its content according to the supplied value.
|
XNElement(java.lang.String name,
java.lang.String namespace)
Constructor.
|
XNElement(java.lang.String name,
java.lang.String namespace,
java.lang.Object value)
Creates a new XElement and sets its content according to the supplied value.
|
| Modifier and Type | Method and Description |
|---|---|
XNElement |
add(java.lang.String name)
Add a new XElement with the given local name and no namespace.
|
XNElement |
add(java.lang.String name,
java.lang.String namespace)
Add a new XElement with the given local name and namespace.
|
XNElement |
add(XNElement child)
Add the given existing child to this element.
|
java.util.Map<XNElement.XAttributeName,java.lang.String> |
attributes() |
XNElement |
childElement(java.lang.String name)
Returns the first child element with the given name.
|
XNElement |
childElement(java.lang.String name,
java.lang.String namespace)
Returns the first child element with the given name.
|
java.util.List<XNElement> |
children() |
java.util.List<XNElement> |
childrenWithName(java.lang.String name)
Returns an iterator which enumerates all children with the given name.
|
java.util.List<XNElement> |
childrenWithName(java.lang.String name,
java.lang.String namespace)
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.
|
java.lang.String |
childValue(java.lang.String name,
java.lang.String namespace)
Returns the content of the first child which has the given name.
|
XNElement |
copy() |
void |
copyFrom(XNElement other)
Copy the attributes and child elements from the other element.
|
protected hu.akarnokd.xml.XNElement.Pair<java.lang.String,java.lang.String> |
createPrefix(java.util.Map<java.lang.String,java.lang.String> nss,
java.lang.String currentNamespace,
java.lang.String currentPrefix)
Generate a new prefix if the current is empty or already exists but with a different URI.
|
void |
detach()
Breaks the link with its parent XElement if any.
|
double |
doubleValue(java.lang.String name,
java.lang.String namespace)
Returns a double value of the supplied child or throws an exception if missing.
|
double |
doubleValue(java.lang.String name,
java.lang.String namespace,
double defaultValue)
Returns a double value or the default value if the element is missing or empty.
|
boolean |
equals(java.lang.Object obj) |
<T> T |
get()
Retrieve the currently associated user object.
|
java.lang.String |
get(java.lang.String attributeName)
Retrieve the first attribute which has the given local attribute name.
|
java.lang.String |
get(java.lang.String attributeName,
java.lang.String attributeNamespace)
Retrieve the specific attribute.
|
java.util.List<XNElement.XAttributeName> |
getAttributeNames()
Retrieve the attribute names.
|
boolean |
getBoolean(java.lang.String attribute)
Retrieve a value of a boolean attribute.
|
boolean |
getBoolean(java.lang.String attribute,
boolean defaultValue)
Retrieve a value of a boolean attribute.
|
boolean |
getBoolean(java.lang.String attribute,
java.lang.String namespace)
Retrieve a value of a boolean attribute.
|
boolean |
getBoolean(java.lang.String attribute,
java.lang.String namespace,
boolean defaultValue)
Retrieve a value of a boolean attribute.
|
double |
getDouble(java.lang.String name)
Returns the attribute as a double value.
|
double |
getDouble(java.lang.String name,
double defaultValue)
Returns the attribute as a double value or the default.
|
double |
getDouble(java.lang.String name,
java.lang.String namespace)
Returns the attribute as a double value.
|
double |
getDouble(java.lang.String name,
java.lang.String namespace,
double defaultValue)
Returns the attribute as a double value or the default.
|
int |
getInt(java.lang.String attribute)
Retrieve an integer attribute.
|
int |
getInt(java.lang.String attribute,
int defaultValue)
Retrieve an integer attribute or the default value if not exists.
|
int |
getInt(java.lang.String attribute,
java.lang.String namespace)
Retrieve an integer attribute or the default value if not exists.
|
int |
getInt(java.lang.String attribute,
java.lang.String namespace,
int defaultValue)
Retrieve an integer attribute or the default value if not exists.
|
long |
getLong(java.lang.String attribute)
Retrieve an long attribute or throw an exception if not exists.
|
long |
getLong(java.lang.String attribute,
long defaultValue)
Retrieve an long attribute or the default value if not exists.
|
long |
getLong(java.lang.String attribute,
java.lang.String namespace)
Retrieve an integer attribute or throw an exception if not exists.
|
long |
getLong(java.lang.String attribute,
java.lang.String namespace,
long defaultValue)
Retrieve an integer attribute or the default value if not exists.
|
java.lang.String |
getXPath() |
boolean |
hasAttribute(java.lang.String name)
Check if the simply-named attribute exists.
|
boolean |
hasAttribute(java.lang.String name,
java.lang.String namespace)
Check if the attribute exists.
|
boolean |
hasAttributes() |
boolean |
hasChildren() |
int |
hashCode() |
boolean |
hasName(java.lang.String name)
Test if this XElement has the given name.
|
boolean |
hasName(java.lang.String name,
java.lang.String namespace)
Test if this XElement has the given name and namespace.
|
int |
intValue(java.lang.String name,
java.lang.String namespace)
Returns an integer value of the supplied child or throws an exception if missing.
|
int |
intValue(java.lang.String name,
java.lang.String namespace,
int defaultValue)
Returns an integer value or the default value if the element is missing or empty.
|
long |
longValue(java.lang.String name,
java.lang.String namespace)
Returns a long value of the supplied child or throws an exception if missing.
|
long |
longValue(java.lang.String name,
java.lang.String namespace,
long defaultValue)
Returns a long value or the default value if the element is missing or empty.
|
static XNElement |
parseXML(byte[] data)
Parse an XML from the binary data.
|
static XNElement |
parseXML(java.io.File file)
Parse an XML from the given file.
|
static XNElement |
parseXML(java.io.InputStream in)
Parse XML from the input stream.
|
static XNElement |
parseXML(java.io.Reader in)
Parse an XML from the given Reader.
|
static XNElement |
parseXML(java.sql.ResultSet rs,
int index)
Reads the contents of a indexed column as an XML.
|
static XNElement |
parseXML(java.sql.ResultSet rs,
java.lang.String column)
Reads the contents of a named column as an XML.
|
static XNElement |
parseXML(java.lang.String fileName)
Parse an XML from the given file.
|
static XNElement |
parseXML(java.net.URL url)
Parse an XML from the supplied URL.
|
static XNElement |
parseXML(javax.xml.stream.XMLStreamReader in)
Parse an XML from the given XML Stream reader.
|
static XNElement |
parseXMLFragment(javax.xml.stream.XMLStreamReader in)
Parses the stream until the end element of the start element is reached, then
returns.
|
static XNElement |
parseXMLGZ(java.io.File file)
Parse an XML file compressed by GZIP.
|
static XNElement |
parseXMLGZ(java.lang.String fileName)
Parse an XML file compressed by GZIP.
|
void |
save(java.io.File file)
Save this XML into the given file.
|
void |
save(java.io.OutputStream stream)
Save this XML into the given output stream.
|
void |
save(java.lang.String fileName)
Save this XML into the given file.
|
void |
save(java.io.Writer stream)
Save this XML into the given writer.
|
void |
save(javax.xml.stream.XMLStreamWriter stream)
Save the tree into the given XML stream writer.
|
protected void |
saveInternal(javax.xml.stream.XMLStreamWriter stream)
Store the element's content and recursively call itself for children.
|
void |
set(java.lang.Object... nameValues)
Set a multitude of attribute names and values.
|
void |
set(java.lang.String name,
java.lang.Object value)
Set an attribute value identified by a local name and no namespace.
|
void |
set(java.lang.String name,
java.lang.String namespace,
java.lang.Object value)
Set an attribute value identified by a local name and namespace.
|
<T> T |
set(T newUserObject)
Replace the associated user object with a new object.
|
java.lang.String |
toString() |
void |
toStringRep(java.lang.String indent,
java.util.Map<java.lang.String,java.lang.String> nss,
XNAppender out,
java.util.function.Consumer<? super XNElement.XRepresentationRecord> callback)
Convert the element into a pretty printed string representation.
|
doubleValue, doubleValue, formatDateTime, formatDateTime, intValue, intValue, longValue, longValue, parseDateTime, sanitize, setValueprotected final java.util.Map<XNElement.XAttributeName,java.lang.String> attributes
protected final java.util.List<XNElement> children
public java.lang.String namespace
public XNElement parent
public java.lang.String prefix
public XNElement(java.lang.String name)
name - the element namepublic XNElement(java.lang.String name,
java.lang.Object value)
name - the element namevalue - the content valuepublic XNElement(java.lang.String name,
java.lang.String namespace)
name - the element namenamespace - the element namespacepublic XNElement(java.lang.String name,
java.lang.String namespace,
java.lang.Object value)
name - the element namenamespace - the namespacevalue - the content valuepublic static XNElement parseXML(byte[] data) throws javax.xml.stream.XMLStreamException
data - the XML datajavax.xml.stream.XMLStreamException - on errorpublic static XNElement parseXML(java.io.File file) throws java.io.IOException, javax.xml.stream.XMLStreamException
file - the filejavax.xml.stream.XMLStreamException - if an error occursjava.io.IOException - if the file could not be found or other I/O error occurspublic static XNElement parseXML(java.io.InputStream in) throws javax.xml.stream.XMLStreamException
in - the InputStream objectjavax.xml.stream.XMLStreamException - if an error occurspublic static XNElement parseXML(java.io.Reader in) throws javax.xml.stream.XMLStreamException
in - the Readerjavax.xml.stream.XMLStreamException - if an error occurspublic static XNElement 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 XNElement 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 XNElement parseXML(java.lang.String fileName) throws java.io.IOException, javax.xml.stream.XMLStreamException
fileName - the file namejavax.xml.stream.XMLStreamException - if an error occursjava.io.IOException - if the file could not be found or other I/O error occurspublic static XNElement parseXML(java.net.URL url) throws java.io.IOException, javax.xml.stream.XMLStreamException
url - the target URLjava.io.IOException - if an I/O error occursjavax.xml.stream.XMLStreamException - if a parser error occurspublic static XNElement parseXML(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException
in stream.in - the XMLStreamReaderjavax.xml.stream.XMLStreamException - if an error occurspublic static XNElement parseXMLFragment(javax.xml.stream.XMLStreamReader in) throws javax.xml.stream.XMLStreamException
in reader.in - the input readerjavax.xml.stream.XMLStreamException - if an error occurspublic static XNElement parseXMLGZ(java.io.File file) throws javax.xml.stream.XMLStreamException
file - the filejavax.xml.stream.XMLStreamException - on errorpublic static XNElement parseXMLGZ(java.lang.String fileName) throws javax.xml.stream.XMLStreamException
fileName - the filenamejavax.xml.stream.XMLStreamException - on errorpublic XNElement add(java.lang.String name)
name - the name of the new elementpublic XNElement add(java.lang.String name, java.lang.String namespace)
name - the name of the new elementnamespace - the namespace of the new elementpublic XNElement add(XNElement child)
child - the child elementpublic java.util.Map<XNElement.XAttributeName,java.lang.String> attributes()
public XNElement childElement(java.lang.String name)
name - the child namepublic XNElement childElement(java.lang.String name, java.lang.String namespace)
name - the child namenamespace - the namespacepublic java.util.List<XNElement> children()
public java.util.List<XNElement> childrenWithName(java.lang.String name)
name - the name of the children to selectpublic java.util.List<XNElement> childrenWithName(java.lang.String name, java.lang.String namespace)
name - the name of the children to selectnamespace - the namespace URIpublic java.lang.String childValue(java.lang.String name)
XElementBasechildValue in class XElementBasename - the child namepublic java.lang.String childValue(java.lang.String name,
java.lang.String namespace)
name - the child namenamespace - the namespace URIpublic XNElement copy()
copy in class XElementBasepublic void copyFrom(XNElement other)
other - the other elementprotected hu.akarnokd.xml.XNElement.Pair<java.lang.String,java.lang.String> createPrefix(java.util.Map<java.lang.String,java.lang.String> nss,
java.lang.String currentNamespace,
java.lang.String currentPrefix)
nss - the namespace to prefix cache.currentNamespace - the current namespacecurrentPrefix - the current prefixpublic void detach()
public double doubleValue(java.lang.String name,
java.lang.String namespace)
name - the child element namenamespace - the element namespacepublic double doubleValue(java.lang.String name,
java.lang.String namespace,
double defaultValue)
name - the element namenamespace - the element namespacedefaultValue - the default valuepublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic <T> T get()
T - the expected object typepublic java.lang.String get(java.lang.String attributeName)
attributeName - the attribute namepublic java.lang.String get(java.lang.String attributeName,
java.lang.String attributeNamespace)
attributeName - the attribute nameattributeNamespace - the attribute namespace URIpublic java.util.List<XNElement.XAttributeName> getAttributeNames()
public boolean getBoolean(java.lang.String attribute)
attribute - the attribute namepublic boolean getBoolean(java.lang.String attribute,
boolean defaultValue)
attribute - the attribute namedefaultValue - the value to return if no such attributepublic boolean getBoolean(java.lang.String attribute,
java.lang.String namespace)
attribute - the attribute namenamespace - the attribute namespacepublic boolean getBoolean(java.lang.String attribute,
java.lang.String namespace,
boolean defaultValue)
attribute - the attribute namenamespace - the attribute namespacedefaultValue - the value to return if no such attributepublic double getDouble(java.lang.String name)
name - the attribute namepublic double getDouble(java.lang.String name,
double defaultValue)
name - the attribute namedefaultValue - the default if the attribute is missingpublic double getDouble(java.lang.String name,
java.lang.String namespace)
name - the attribute namenamespace - the attribute namespacepublic double getDouble(java.lang.String name,
java.lang.String namespace,
double defaultValue)
name - the attribute namenamespace - the attribute namespacedefaultValue - the default if the attribute is missingpublic int getInt(java.lang.String attribute)
attribute - the attribute namepublic int getInt(java.lang.String attribute,
int defaultValue)
attribute - the attribute namedefaultValue - the default value to returnpublic int getInt(java.lang.String attribute,
java.lang.String namespace)
attribute - the attribute namenamespace - the attribute namespace URIpublic int getInt(java.lang.String attribute,
java.lang.String namespace,
int defaultValue)
attribute - the attribute namenamespace - the namespace URIdefaultValue - the default value to returnpublic long getLong(java.lang.String attribute)
attribute - the attribute namepublic long getLong(java.lang.String attribute,
long defaultValue)
attribute - the attribute namedefaultValue - the default value to returnpublic long getLong(java.lang.String attribute,
java.lang.String namespace)
attribute - the attribute namenamespace - the attribute namespace URIpublic long getLong(java.lang.String attribute,
java.lang.String namespace,
long defaultValue)
attribute - the attribute namenamespace - the attribute namespace URIdefaultValue - the default value to returnpublic java.lang.String getXPath()
public boolean hasAttribute(java.lang.String name)
name - the name of the attributepublic boolean hasAttribute(java.lang.String name,
java.lang.String namespace)
name - the attribute namenamespace - the attribute namespacepublic boolean hasAttributes()
public boolean hasChildren()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean hasName(java.lang.String name)
name - the name to test againstpublic boolean hasName(java.lang.String name,
java.lang.String namespace)
name - the name to test againstnamespace - the namespace to test againstpublic int intValue(java.lang.String name,
java.lang.String namespace)
name - the child element namenamespace - the element namespacepublic int intValue(java.lang.String name,
java.lang.String namespace,
int defaultValue)
name - the element namenamespace - the element namespacedefaultValue - the default valuepublic long longValue(java.lang.String name,
java.lang.String namespace)
name - the child element namenamespace - the element namespacepublic long longValue(java.lang.String name,
java.lang.String namespace,
long defaultValue)
name - the element namenamespace - the element namespacedefaultValue - the default valuepublic 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 stream)
throws java.io.IOException
stream - the output writerjava.io.IOException - on errorpublic void save(javax.xml.stream.XMLStreamWriter stream)
throws javax.xml.stream.XMLStreamException
stream - the stream writerjavax.xml.stream.XMLStreamException - if an error occursprotected void saveInternal(javax.xml.stream.XMLStreamWriter stream)
throws javax.xml.stream.XMLStreamException
stream - the stream outputjavax.xml.stream.XMLStreamException - if an error occurspublic void set(java.lang.Object... nameValues)
nameValues - the attribute name and attribute value pairs.public void set(java.lang.String name,
java.lang.Object value)
name - the attribute namevalue - the value, if null, the attribute will be removedpublic void set(java.lang.String name,
java.lang.String namespace,
java.lang.Object value)
name - the attribute namenamespace - the attribute namespacevalue - the value, if null, the attribute will be removedpublic <T> T set(T newUserObject)
T - the object typenewUserObject - the new user objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic void toStringRep(java.lang.String indent,
java.util.Map<java.lang.String,java.lang.String> nss,
XNAppender out,
java.util.function.Consumer<? super XNElement.XRepresentationRecord> callback)
indent - the current line indentationnss - the namespace cacheout - the outputcallback - the callback for each element and text position.