public class XMap extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
protected static String |
DEFAULT_ROOT_NAME |
static XMap |
EMPTY_XMAP
An empty and unmodifiable XMap instance.
|
| Modifier | Constructor and Description |
|---|---|
|
XMap()
Constructs a new XMap instance.
|
|
XMap(Element root)
Constructs a new XMap instance.
|
|
XMap(InputStream input)
Constructs a new XMap instance from an XML input stream.
|
|
XMap(InputStream input,
EntityResolver resolver)
Constructs a new XMap instance from an XML input stream.
|
|
XMap(String root)
Constructs a new XMap instance.
|
|
XMap(XMap map)
Constructs a new XMap instance based on an existing XMap and clone its content.
|
protected |
XMap(XMLUtil xmlUtil,
Element root,
boolean clone)
Constructs a new XMap instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsKey(String key)
Returns true if the supplied key XPath expression matches at least one element, attribute
or text in the root element of this XMap.
|
String |
get(String key)
Returns the text value of the element (or attribute or text) that matches the supplied
XPath expression.
|
<T> T |
get(String key,
Class<T> clazz,
T defaultValue) |
<T> T |
get(String key,
Class<T> clazz,
T defaultValue,
boolean required,
boolean warn) |
List<XMap> |
getAll(String key)
Returns a list of XMap instances with all elements that match the
supplied XPath expression.
|
XMap |
getOne(String key)
Returns a new XMap instance with the first element that matches the
supplied XPath expression or null if this XMap root element is null, or if XPath evaluation
result is null, or this result is not an Element.
|
Element |
getRoot()
Allows direct manipulation of the root element.
|
String |
put(String key,
String value)
Creates or updates the text value of the element (or text or attribute) matched by
the supplied XPath expression.
|
String |
put(String key,
String value,
boolean append)
Creates or updates the text value of the element (or text or attribute) matched by
the supplied XPath expression.
|
String |
remove(String key)
Removes the element, text or attribute that matches the supplied XPath expression.
|
String |
toString()
Returns a "pretty" XML representation of the root element of this XMap (may be null).
|
protected static final String DEFAULT_ROOT_NAME
public static final XMap EMPTY_XMAP
public XMap()
public XMap(String root)
root - the name of the root element (may be null).public XMap(InputStream input) throws IOException, SAXException
input - an XML input stream.IOExceptionSAXExceptionpublic XMap(InputStream input, EntityResolver resolver) throws IOException, SAXException
input - an XML input stream.IOExceptionSAXExceptionpublic XMap(Element root)
root - a DOM element (may be null).public XMap(XMap map)
map - the map to duplicate (root element is cloned so modification to this
new instance won't modify the original XMap).public Element getRoot()
public boolean containsKey(String key)
key - an XPath expression.RuntimeException - if the XPath expression isn't correct.public String get(String key)
key - an XPath expression.RuntimeException - if the XPath expression isn't correct.public List<XMap> getAll(String key)
key - an XPath expression.RuntimeException - if the XPath expression isn't correct.public XMap getOne(String key)
key - an XPath expression.RuntimeException - if the XPath expression isn't correct.public String put(String key, String value)
key - an XPath expression.value - the value to set (may be null).RuntimeException - if the root element of this XMap is null, if the XPath expression is not valid,
or (creation case) if the parent node does not exist or is not an element instance.public String put(String key, String value, boolean append)
key - an XPath expression.value - the value to set (may be null).append - should the new element be appended (created) next to a possibly existing element(s) of
the same name?RuntimeException - if the root element of this XMap is null, if the XPath expression is not valid,
or (creation case) if the parent node does not exist or is not an element instance.public String remove(String key)
key - an XPath expression.RuntimeException - if the XPath expression isn't valid.