Package org.xembly
Class Xembler
java.lang.Object
org.xembly.Xembler
Processor of Xembly directives, main entry point to the package.
For example, to modify a DOM document:
Document dom = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); dom.appendChild(dom.createElement("root")); new Xembler( new Directives() .xpath("/root") .addIfAbsent("employees") .add("employee") .attr("id", 6564) ).apply(dom);
You can also convert your Xembly directives directly to XML document:
String xml = new Xembler( new Directives() .xpath("/root") .addIfAbsent("employees") .add("employee") .attr("id", 6564) ).xml("root");
Since version 0.18 you can convert directives to XML without
a necessity to catch checked exceptions.
Use *Quietly()
methods for that:
xmlQuietly()
, domQuietly()
,
and applyQuietly(Node)
.
- Since:
- 0.1
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionApply all changes to the document/node.applyQuietly
(Node dom) Apply all changes to the document/node, without any checked exceptions.dom()
Apply all changes to an empty DOM.Apply all changes to an empty DOM, without checked exceptions.static String
Utility method to escape text before using it as a text value in XML.xml()
Convert to XML document.Convert to XML document, without checked exceptions.
-
Constructor Details
-
Xembler
Public ctor.- Parameters:
dirs
- Directives
-
Xembler
Public ctor.- Parameters:
directives
- Directivestransformers
- Transformers
-
-
Method Details
-
applyQuietly
Apply all changes to the document/node, without any checked exceptions.- Parameters:
dom
- DOM document/node- Returns:
- The same document/node
- Since:
- 0.18
-
apply
Apply all changes to the document/node.- Parameters:
dom
- DOM document/node- Returns:
- The same document/node
- Throws:
ImpossibleModificationException
- If can't modify
-
domQuietly
Apply all changes to an empty DOM, without checked exceptions.- Returns:
- DOM created
- Since:
- 0.18
-
dom
Apply all changes to an empty DOM.- Returns:
- DOM created
- Throws:
ImpossibleModificationException
- If can't modify- Since:
- 0.9
-
xmlQuietly
Convert to XML document, without checked exceptions.- Returns:
- XML document
- Since:
- 0.18
-
xml
Convert to XML document.- Returns:
- XML document
- Throws:
ImpossibleModificationException
- If can't modify- Since:
- 0.9
-
escape
Utility method to escape text before using it as a text value in XML.Use it like this, in order to avoid runtime exceptions:
new Directives().xpath("/test") .set(Xembler.escape("illegal: "));
- Parameters:
text
- Text to escape- Returns:
- The same text with escaped characters, which are not XML-legal
- Since:
- 0.14
- Suppressed Checkstyle violations:
- CyclomaticComplexity (20 lines), BooleanExpressionComplexity (20 lines)
-