A lightweight Java library for parsing, creating, and manipulating XML documents. It provides a simple API for working with XML data.
- Create XML documents programmatically
- Parse XML from strings
- Manipulate XML nodes, attributes, and text content
- Flexible node and attribute management
- Easy serialization to XML string format
- Support for nested nodes and complex XML structures
StringView
support for flexible conversion ofXmlAttribute
name and value andXmlNode
tag and text
The library depends on StringView to provide functionality for XmlAttribute
name and value and XmlNode
tag and text view.
The core class representing an XML element with the following capabilities:
- Add, remove, and manage child nodes
- Add, remove, and manipulate attributes
- Set and retrieve text content
- Serialize to XML string with customizable indentation
Represents XML attributes with:
- Name and value management
- Unique attribute name validation
Contains helper methods for creating specific predicates for nodes and attributes.
XmlNode root = new XmlNode();
root.setTag("root");
XmlNode book = root.addNode("foo");
book.addAttribute("bar").setValue(64);
book.setText("The foo");
XmlNode author = book.addNode("baz");
author.setText("The baz");
String xmlString = root.toXmlString();
XmlNode parsedDocument = new XmlNode("<root><foo id='105'>The foo</foo></root>");
XmlNode foo = parsedDocument.getNode("foo");
String id = book.getAttribute("id").getValue().toString();
List<XmlNode> filteredNodes = xmlNode.getNodes(node ->
node.hasAttribute("repo") &&
node.getAttribute("repo").getValue().equals("central")
);
xmlNode.sortNodes(Comparator.comparing(node ->
node.getAttribute("id").getValue().toString()
));
addNode(String tag)
: Add a new child nodegetNode(String tag)
: Retrieve a child node by tagremoveNode(String tag)
: Remove a specific nodegetAttributes()
: Get all attributesaddAttribute(String name)
: Add a new attributesetText(String text)
: Set node text contentviewText()
: Create aStringView
for the text content
setName(String name)
: Set attribute namesetValue(String value)
: Set attribute valueviewValue()
: Create aStringView
for the value
- Throws
IllegalArgumentException
for duplicate attribute names - Provides methods to safely access and manipulate XML structures
This project is licensed under the MIT License - see the LICENSE file for details.