xsylum

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

Categories

Categories

Net
GroupId

GroupId

net.jodah
ArtifactId

ArtifactId

xsylum
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

xsylum
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://github.com/jhalterman/xsylum/
Source Code Management

Source Code Management

http://github.com/jhalterman/xsylum/

Download xsylum

How to add to project

<!-- https://jarcasting.com/artifacts/net.jodah/xsylum/ -->
<dependency>
    <groupId>net.jodah</groupId>
    <artifactId>xsylum</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.jodah/xsylum/
implementation 'net.jodah:xsylum:0.1.0'
// https://jarcasting.com/artifacts/net.jodah/xsylum/
implementation ("net.jodah:xsylum:0.1.0")
'net.jodah:xsylum:jar:0.1.0'
<dependency org="net.jodah" name="xsylum" rev="0.1.0">
  <artifact name="xsylum" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.jodah', module='xsylum', version='0.1.0')
)
libraryDependencies += "net.jodah" % "xsylum" % "0.1.0"
[net.jodah/xsylum "0.1.0"]

Dependencies

test (1)

Group / Artifact Type Version
org.testng : testng jar 6.1.1

Project Modules

There are no modules declared in this project.

Xsylum Build Status

XML parsing and DOM traversal for the sane.

Introduction

Why XML? Why indeed.

But let's say you're working with some legacy services where XML is the thing. And you discover that the available XML parser APIs are bad. Really bad. What do you? Maybe you use Xsylum, that's what.

Xsylum is a dead simple, zero-dependency wrapper around the Java XML parser API. It's mostly intended for read operations, opting to traverse nodes on demand (when searching children) instead of eagerly building a separate DOM.

Setup

Add Xsylum as a Maven dependency:

<dependency>
  <groupId>net.jodah</groupId>
  <artifactId>xsylum</artifactId>
  <version>0.1.0</version>
</dependency>

Usage

// Parse some XML to a document
XmlDocument document = Xsylum.documentFor(xmlFile);

// Access the root element for the document
XmlElement element = document.root();

// Parse some XML to a root element
XmlElement element = Xsylum.elementFor(xmlFile);

// Access element attributes
Map<String, String> attributes = element.attributes();
String id = element.attribute("id");

// Access child elements
List<XmlElement> children = element.children();

// Search child elements
List<XmlElement> authors = document.getAll("author");
List<XmlElement> books = element.getAll("book");
XmlElement book = element.get("book");

// Access the value of an element
String value = book.value();
int value = book.get("copies-sold").valueAsInt();

// Find child elements for XPath expressions
XmlElement author = document.find("/catalog/book[2]/author");
List<XmlElement> authors = document.findAll("//author");

// Find values for XPath expressions
String author = document.value("//author/text()");
int copiesSold = book.valueAsInt(".//copies-sold/text()");
List<String> authors = document.values("/catalog/book/author/text()");
List<Integer> allCopiesSold = document.valuesAsInt("/catalog/book/copies-sold/text()");

Docs

JavaDocs are available here.

License

Copyright 2014 Jonathan Halterman - Released under the Apache 2.0 license.

Versions

Version
0.1.0