All Projects → jhannes → eaxy

jhannes / eaxy

Licence: other
Eaxy - Enjoy XML. Java library for parsing, building and iterating both simple and huge + complex XML

Programming Languages

java
68154 projects - #9 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to eaxy

Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (+3628.85%)
Mutual labels:  xml-parser
Pugixml
Light-weight, simple and fast XML parser for C++ with XPath support
Stars: ✭ 2,809 (+5301.92%)
Mutual labels:  xml-parser
laravel-helper-functions
Laravel-specific and pure PHP Helper Functions.
Stars: ✭ 106 (+103.85%)
Mutual labels:  xml-parser
Web Database Analytics
Web scrapping and related analytics using Python tools
Stars: ✭ 175 (+236.54%)
Mutual labels:  xml-parser
Saxy
A fast, easy-to-use and XML 1.0 compliant XML SAX parser in Elixir
Stars: ✭ 192 (+269.23%)
Mutual labels:  xml-parser
Webpageparser
A delightful xml and html parsing relish for iOS
Stars: ✭ 236 (+353.85%)
Mutual labels:  xml-parser
Woodstox
The gold standard Stax XML API implementation. Now at Github.
Stars: ✭ 145 (+178.85%)
Mutual labels:  xml-parser
DocSum
A tool to automatically summarize documents abstractively using the BART or PreSumm Machine Learning Model.
Stars: ✭ 58 (+11.54%)
Mutual labels:  xml-parser
Xmlquery
xmlquery is Golang XPath package for XML query.
Stars: ✭ 209 (+301.92%)
Mutual labels:  xml-parser
xmltree-rs
Reads an XML file into a simple tree structure
Stars: ✭ 33 (-36.54%)
Mutual labels:  xml-parser
Dlib
Allocators, I/O streams, math, geometry, image and audio processing for D
Stars: ✭ 182 (+250%)
Mutual labels:  xml-parser
Parse Xml
A fast, safe, compliant XML parser for Node.js and browsers.
Stars: ✭ 184 (+253.85%)
Mutual labels:  xml-parser
Ruby Nmap
A Ruby interface to nmap, the exploration tool and security / port scanner. Allows automating nmap and parsing nmap XML files.
Stars: ✭ 244 (+369.23%)
Mutual labels:  xml-parser
Parser
📜 XML Document Parser for PHP
Stars: ✭ 171 (+228.85%)
Mutual labels:  xml-parser
representable
Maps representation documents from and to Ruby objects. Includes JSON, XML and YAML support, plain properties and compositions.
Stars: ✭ 689 (+1225%)
Mutual labels:  xml-parser
Xml2lua
XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
Stars: ✭ 150 (+188.46%)
Mutual labels:  xml-parser
Posthtml
PostHTML is a tool to transform HTML/XML with JS plugins
Stars: ✭ 2,737 (+5163.46%)
Mutual labels:  xml-parser
xavier
Xavier is a small object-oriented XML library for Lazarus and Delphi
Stars: ✭ 38 (-26.92%)
Mutual labels:  xml-library
exml
Most simple Elixir wrapper for xmerl xpath
Stars: ✭ 23 (-55.77%)
Mutual labels:  xml-parser
koa-xml-body
koa middleware to parse xml request body
Stars: ✭ 36 (-30.77%)
Mutual labels:  xml-parser

EAXY - An easy to use XML library for Java

Maven Central Build Status Coverage Status

EAXY is a fluent Java library for building, parsing, searching and manipulating XML. It aims to have a compact syntax for doing the most common operations on XML and HTML trees. It is designed to be pleasant to use, both when you work with simple and small XML files and when you work with huge, poorly structured or deeply nested XML files where code generation is not feasible.

It's very suitable for building XML structures to use in unit tests.

Eaxy is small (< 100 kB) and has no dependencies.

Overview

EAXY is build with the following guiding principles:

  • Namespaces must be build in from the start
  • Links to parent nodes and document complicates the design and imposes problems with copying subtres
  • Libraries should prefer reimplementing trivial code over adding dependencies

Features:

  1. Parse large XML documents (a 90 MB document in 3 seconds!): for (Element subtree : Xml.filter("html", "body", "ul", "li").iterate(reader))
  2. Build complex XML documents with a simple internal DSL Xml.el("html", Xml.el("body", Xml.el("h4", "A message")))
  3. Flexibly traverse complex XML documents doc.find("body", "h4").check().text(); doc.find("body", "ul", "li").texts()
  4. Experimental: Random XML services for testing SoapSimulatorServer server = new SoapSimulatorServer(10080); server.addSoapEndpoint(...); server.start();

Design:

Class diagram

Building XML documents:

Namespace A_NS = new Namespace("uri:a", "a");
Namespace B_NS = new Namespace("uri:b", "b");

Element xml = A_NS.el("root",
        Xml.el("node-without-namespace", "element text"), 
        A_NS.el("parent", 
                A_NS.el("child")),
        B_NS.el("other-parent", Xml.text("Here's some text")));

Manipulating XML documents:

Element div = el("div");
assertThat(div.className()).isNull();
div.addClass("important");
div.addClass("hidden");
assertThat(div.className()).isEqualTo("important hidden");
div.removeClass("hidden");
div.removeClass("hidden");
assertThat(div.className()).isEqualTo("important");
div.removeClass("important");
assertThat(div.className()).isEmpty();

Finding contents in XML documents:

Element xml = el("div",
        el("div").id("not-here").add(text("something")),
        el("div").id("below-here").add(
                el("div", el("div", el("p", text("around "), el("span", "HERE"), text(" around"))))));
assertThat(xml.find("...", "#below-here", "...", "p", "...").first().text())
    .isEqualTo("HERE");

Streaming large files:

ElementQuery filter = Xml.filter("parentElement", "childElement");
try (Reader reader = new FileReader(hugeFile)) {
    for (Element element : filter.iterate(reader)) {
        if ("active".equals(element.find("status").first().attr("value"))) {
            System.out.println(element.find("description", "name").first().text());
        }
    }
}

HTML utilities:

Element form = el("form",
        el("input").id("first_name_id").name("first_name").type("text").val("Darth"),
        el("input").id("last_name_id").name("last_name").type("text").val("Vader"),
        el("input").name("createPerson").type("submit").val("Create person"));
assertThat(form.find("input").ids()).containsExactly("first_name_id", "last_name_id");
assertThat(form.find("input").values()).containsExactly("Darth", "Vader", "Create person");
assertThat(form.find("input").names()).containsExactly("first_name", "last_name", "createPerson");

assertThat(form.find("input").first().val()).isEqualTo("Darth");

Generating sample XMLs from XSD (experimental):

SampleSoapXmlBuilder builder = new SampleSoapXmlBuilder("xsd/StockQuoteService.wsdl");
Element output = builder
     .service("StockQuoteService")
     .operation("GetLastTradePrice")
     .randomOutput("m");
assertThat(output.tagName()).isEqualTo("TradePrice");
double price = Float.parseFloat(output.find("price").single().text());


SampleXmlBuilder generator = new SampleXmlBuilder(getClass().getResource("/xsd/po.xsd"), "po");
generator.setFull(true);
Element el = generator.createRandomElement("purchaseOrder");
assertThat(el.hasAttr("orderDate")).isTrue();
assertThat(el.find("comment")).isNotEmpty();
assertThat(el.find("items").check().find("item")).isNotEmpty();
assertThat(el.find("shipTo").single().attr("country")).isEqualTo("US");
generator.getValidator().validate(el);

Known issues:

  • SAX namespace may be broken with certain classpath combinations - perhaps I need to write my own parser
  • Finding doesn't include the current element, which is often non-intuitive
  • The "..." syntax is unintuitive and could use some improvement
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].