FluentXML4J - a fluent API for XML in Java
![License](https://camo.githubusercontent.com/2a2157c971b7ae1deb8eb095799440551c33dcf61ea3d965d86b496a5a65df55/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667)
XML parsing, serialization XPath querying and transformation without boilerplate code
Features
- Simple, fluent API but full flexibility
- Parse from java.io inputs to org.w3c.dom.Document
- Serialize org.w3c.dom.Document to any java.io output
- Transform from java.io, SAX, StAX, JAXB input to any of them with XSLT and custom filters support
- Query org.w3c.dom.Document via XPath for String, Boolean, Number, org.w3c.dom.Element or Node, get the results as collections or process with the Java 8 Streaming API
- Validate document against schemas
- No (required) dependencies
Requirements
FluentXML4J uses the builtin JDK XML parser and XPath API, but Java 8 is required because of streaming API and Optional support.
Maven Dependency
<dependency>
<groupId>com.github.fluentxml4j</groupId>
<artifactId>fluentxml4j-core</artifactId>
<version>2.2.1</version>
</dependency>
Examples
Parsing
Document doc = parse(getClass().getResourceAsStream("example.xml"))
.document();
Serialization
serialize(document).to(System.err);
More serialization examples...
Transformation
Document resultDoc = transform(inputDoc)
.withStylesheet(xsltInputStream)
.toDocument();
More transformation examples...
XPath Querying
List<Element> elements = from(doc)
.selectElements("//*")
.asList();
Similar and related Projects
- xmltool - another fluent API for XML
- dom4j - alternative DOM implementation
- jdom - alternative DOM implementation
- XMLDog - a XML stream sniffer
Contributing
FluentXML4J is an open source project, and contributions are welcome! Feel free to raise an issue or submit a pull request.
License
Copyright (c) 2017 by Cornelius Buschka.