Querying an Element

Querying an Element List

  1. String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
  2. SpinList<SpinXmlTreeElement> childs = XML(xml).xPath("/root/child/a").elementList();

Querying an Attribute

  1. String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
  2. SpinXmlTreeAttribute attribute = XML(xml).xPath("/root/child/@id").attribute();

Querying an Attribute List

Querying a String

  1. import static org.camunda.spin.Spin.XML;
  2. String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";

Querying a Number

  1. import static org.camunda.spin.Spin.XML;
  2. String xml = "<root><child id=\"child\"><a id=\"a\"/><a id=\"b\"/></child></root>";
  3. Double count = XML(xml).xPath("count(/root/child/a)").number();

Querying a Boolean

Querying with Namespaces

  1. import static org.camunda.spin.Spin.XML;
  2. String xml = "<root xmlns:t=\"http://camunda.org\"><t:child id=\"child\"><a id=\"a\"/></t:child></root>";
  3. SpinXmlTreeElement child = XML(xml).xPath("/root/t:child")
  4. .ns("t", "http://camunda.org");
  5. .element();

2. Using a Map of Prefix - URI Pairs

  1. import static org.camunda.spin.Spin.XML;
  2. String xml = "<root xmlns:t=\"http://camunda.org\"><t:child id=\"child\"><a id=\"a\"/></t:child></root>";
  3. Map<String, String> namespaceMap = new HashMap<String, String>();
  4. namespaceMap.put("t", "http://camunda.org");
  5. namespaceMap.put("s", "http://camunda.com");
  6. SpinXmlTreeElement child = XML(xml).xPath("/root/t:child")
  7. .ns(namespaceMap);