XML Parsing and Printing
Set of classes in com.jcabi.xml
is an extra layer on top of DOM that allows simple parsing, printing, and transforming of XML documents and nodes:
public class Main { public static void main(String[] args) { XML xml = new XMLDocument( "<orders><order id="4">Coffee to go</order></orders>" ); String id = xml.xpath("//order/@id").get(0); String name = xml.xpath("//order[@id=4]/text()"); System.out.println(xml.toString()); } }
The only dependency you need is (you can also download jcabi-xml-0.32.0.jar
and add it to the classpath):
<dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-xml</artifactId> <version>0.32.0</version> </dependency>
Cutting Edge Version
If you want to use current version of the product, you can do it with this configuration in your pom.xml
:
<repositories> <repository> <id>oss.sonatype.org</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.jcabi</groupId> <artifactId>jcabi-xml</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>