public class XmlDynamic extends AbstractDynamic<Node>
Weak.convert()
to implement basic string->type conversions
As an example consider the following XML structure stored in a String 'xmlMessage'
<product>
<investment>
<info>
<current>
<name>some name</name>
</current>
</info>
</investment>
</product>
We can select the nested 'name' element value with
new XmlDynamic(xmlMessage).get("product.investment.info.current.name", ".").asString()
Also since XML has certain key name restrictions the pipe character '|' can be used as a splitter without declaration
ie new XmlDynamic(xmlMessage).get("product|investment|info|current|name").asString()
get(Object)inner| Constructor and Description |
|---|
XmlDynamic(InputSource xml) |
XmlDynamic(Node inner) |
XmlDynamic(Reader xml) |
XmlDynamic(String xml) |
| Modifier and Type | Method and Description |
|---|---|
String |
asObject()
Returns inner value implicitly asserting that the value is not absent, ie
Weak.isPresent() is true |
protected Stream<alexh.weak.XmlDynamic.Child> |
attributes() |
protected Stream<alexh.weak.XmlDynamic.Child> |
attributesWith(Predicate<Node> predicate) |
Stream<Dynamic> |
children() |
String |
describe() |
protected Stream<alexh.weak.XmlDynamic.Child> |
elements() |
protected Stream<alexh.weak.XmlDynamic.Child> |
elementsWith(Predicate<Node> predicate) |
boolean |
equals(Object o) |
String |
fullXml() |
Dynamic |
get(Object keyObject)
Returns a dynamic wrapping the immediate child of this instance with the input key,
or a dynamic representing the lack of such a child.
|
protected Dynamic |
getWithNamespace(String namespace,
String key) |
static Predicate<? super Dynamic> |
hasElementName(String elementName)
Predicate for an xml element's name as it appears in the xml itself (case insensitive)
Inside the xml dynamic multiple elements with the same names have unique suffices ie
dynamic -> dynamic.key().asString().equals("child") would only match the first
hasElementName("child") matches both |
int |
hashCode() |
boolean |
is(Class<?> type)
Dynamic Xml values are always
Strings |
protected Object |
keyLiteral() |
protected LSSerializer |
serializer() |
String |
toString() |
isPresent, keyclone, finalize, getClass, notify, notifyAll, wait, wait, waitallChildren, allChildrenBreadthFirst, allChildrenDepthFirst, as, dget, from, getpublic XmlDynamic(Node inner)
public XmlDynamic(InputSource xml)
public XmlDynamic(Reader xml)
public XmlDynamic(String xml)
public static Predicate<? super Dynamic> hasElementName(String elementName)
dynamic -> dynamic.key().asString().equals("child") would only match the first
hasElementName("child") matches bothelementName - xml element namepublic Dynamic get(Object keyObject)
The pipe character '|' can be used as a splitter without declaration
ie xmlDynamic.get("product|investment|info|current|name").asString().
Multiple child elements with the same local-name effectively have [i] appended to them where i is their
index counting from top to bottom.
For example:
<product id="1234">
<string>hello</string>
<string>hey</string>
<string>hi</string>
<string>howdy</string>
</product>
xmlDynamic.get("product|string") returns "hello"
xmlDynamic.get("product|string[0]") also returns "hello"
xmlDynamic.get("product|string[1]") returns "hey"
xmlDynamic.get("product|string[2]") returns "hi"
xmlDynamic.get("product|string[3]") returns "howdy"
Attributes can be accessed in exactly the same way as elements, or explicitly
xmlDynamic.get("product|id").asString() return "1234"
xmlDynamic.get("product|@id").asString() also returns "1234"
Namespaces are ignored by default, but can be used explicitly using the "::" separator For example:
<ex:product xmlns:ex="http://example.com/example">
<message>hello</message>
</ex:product>
xmlDynamic.get("product|message") returns "hello"
xmlDynamic.get("http://example.com/example::product|none::message") also returns "hello"protected Stream<alexh.weak.XmlDynamic.Child> attributes()
protected Stream<alexh.weak.XmlDynamic.Child> attributesWith(Predicate<Node> predicate)
protected Stream<alexh.weak.XmlDynamic.Child> elements()
protected Object keyLiteral()
keyLiteral in class AbstractDynamic<Node>public String describe()
public int hashCode()
hashCode in class AbstractDynamic<Node>public boolean equals(Object o)
equals in class AbstractDynamic<Node>protected LSSerializer serializer()
public String asObject()
WeakWeak.isPresent() is truepublic String fullXml()
Copyright © 2017. All rights reserved.