use of com.jcabi.xml.XMLDocument in project wring by yegor256.
the class XePrint method text.
/**
* Render text via XPath.
* @param pattern Pattern to use
* @return Plain text
*/
public String text(final CharSequence pattern) {
final XML xml = new XMLDocument(new Xembler(this.dirs).domQuietly());
final Pattern ptn = Pattern.compile("\\{([^}]+)}");
final Matcher mtr = ptn.matcher(pattern);
final StringBuffer out = new StringBuffer(pattern.length());
while (mtr.find()) {
mtr.appendReplacement(out, xml.xpath(mtr.group(1)).get(0).replace("\\", "\\\\").replace("$", "\\$"));
}
mtr.appendTail(out);
return out.toString();
}
use of com.jcabi.xml.XMLDocument in project jcabi-github by jcabi.
the class JsonNodeTest method convertsXmlToJson.
/**
* JsonNode can text XML to JSON.
* @throws Exception If some problem inside
*/
@Test
public void convertsXmlToJson() throws Exception {
final XML xml = new XMLDocument("<user><name>Jeff</name><dept><title>IT</title></dept></user>");
final JsonObject json = new JsonNode(xml.nodes("user").get(0)).json();
MatcherAssert.assertThat(json, Matchers.notNullValue());
MatcherAssert.assertThat(json.getString("name"), Matchers.equalTo("Jeff"));
MatcherAssert.assertThat(json.getJsonObject("dept").getString("title"), Matchers.equalTo("IT"));
}
Aggregations