Querying an Element
Querying an Element List
String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
SpinList<SpinXmlTreeElement> childs = XML(xml).xPath("/root/child/a").elementList();
Querying an Attribute
String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
SpinXmlTreeAttribute attribute = XML(xml).xPath("/root/child/@id").attribute();
Querying an Attribute List
Querying a String
import static org.camunda.spin.Spin.XML;
String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
Querying a Number
import static org.camunda.spin.Spin.XML;
String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
Double count = XML(xml).xPath("count(/root/child/a)").number();
Querying a Boolean
Querying with Namespaces
import static org.camunda.spin.Spin.XML;
String xml = "<root xmlns:t=\"http://camunda.org\"><t:child id=\"child\"><a id=\"a\"/></t:child></root>";
SpinXmlTreeElement child = XML(xml).xPath("/root/t:child")
.ns("t", "http://camunda.org");
.element();
2. Using a Map of Prefix - URI Pairs
import static org.camunda.spin.Spin.XML;
String xml = "<root xmlns:t=\"http://camunda.org\"><t:child id=\"child\"><a id=\"a\"/></t:child></root>";
Map<String, String> namespaceMap = new HashMap<String, String>();
namespaceMap.put("t", "http://camunda.org");
namespaceMap.put("s", "http://camunda.com");
SpinXmlTreeElement child = XML(xml).xPath("/root/t:child")
.ns(namespaceMap);