Skip to content

mschrag/xiss

Repository files navigation

XISS

XISS is a simple xml parsing/building library for Java. The goal is to provide a very simple
and very terse API for building XML documents in Java code. XISS does NOT implement the full
set of features of the W3C DOM API’s — if you need something fancier, use JDOM. If you just
need to build simple documents in code, XISS might be worth a look.

Building

There are a couple ways you can build XML documents with XISS.

The first way uses varargs. This is the shortest way, but might choke if your IDE doesn’t respect newlines:


XML.Doc doc = XML.doc(
    XML.comment("This is the structure for a person"),
    XML.e("person",
        XML.e("first-name", "Mike"),
        XML.e("last-name", "Schrag"),
        XML.e("addresses",
            XML.e("address",
                XML.a("location", "Home"),
                XML.e("address", "100 Main St."),
                XML.e("city", "Richmond"),
                XML.e("state", "VA"),
                XML.e("zip", "23233")
            ),
            XML.cdata("This is a cdata section! <test> of cdata!")
        )
    )
);

The other way is more verbose, but will always format properly in your IDE:


XML.Doc doc = XML.doc();
doc.comment("This is the structure for a person");
XML.E person = doc.root("person");
{
  person.e("first-name", "Bob");
  person.e("last-name").setText("Jones");
  person.comment("This is the structure for addresses");
  XML.E addresses = person.e("addresses");
  {
    XML.E homeAddress = addresses.e("address").set("location", "Home");
    {
      homeAddress.e("address", "100 Main St");
      homeAddress.e("city", "Richmond");
      homeAddress.e("state", "VA");
      homeAddress.e("zip", "23233");
    }
    addresses.cdata("This is a cdata section! <test> of cdata!");
  }
}

Parsing

Parsing just uses the W3C DOM parsers underneath, but wrapped to make them easier:


XML.Doc doc = XML.doc(String)
XML.Doc doc = XML.doc(File)
XML.Doc doc = XML.doc(Reader)

Printing

The toString of XISS DOM objects just return pretty-print XML:

System.out.println(doc);


<?xml version="1.0" encoding="UTF-8"?>
<!-- This is the structure for a person -->
<person>
  <first-name>Bob</first-name>
  <last-name>Jones</last-name>
  <!-- This is the structure for addresses -->
  <addresses>
    <address location="Home">
      <address>100 Main St</address>
      <city>Richmond</city>
      <state>VA</state>
      <zip>23233</zip>
    </address>
    <![CDATA[This is a cdata section! <test> of cdata!]]>
  </addresses>
</person>

Examples

There are more examples of things you can do in the “example” folder.

About

Simple XML builder/parser API for Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages