Home - scalawag/sdom GitHub Wiki

SDOM is a library for processing XML in a Scala-ish kind of way.

Why?

The biggest problem with other Scala XML libraries out there is weak support for complex documents using multiple namespaces. It's also not particularly easy to have several components collaborate to produce a single, consistent XML document with multiple namespaces. SDOM solves this with the notion of "specifications" which specify the important semantic parts of an XML document. That includes virtually everything except for namespace prefixes and declarations. Documents which can be queried, serialized, and transformed are built from these specifications.

Namespace prefixes and the locations of the namespace declarations are not considered important by default. You can always force parts of the resulting document that are important to you but as a mostly machine-readable format, those are just mappings. They can aid readability but you never perform selections against the QName of an element or attribute. All Elements and Attributes have a local name and a namespace that are always retained as specified. This lets the computer do the work of making sure that your namespaces are all declared as efficiently as possible for you.

Specifications can be built in a number of ways:

  • Conversion from Scala XML literals
  • Using the specification case class constructors
  • From an existing document (e.g., after parsing from a file or string)
  • Transforming an existing Document into a new document specification

Features

Once you have a Document, SDOM has a lot of great features to help you utilize it.

Features include:

  • Simple node selection, similar to the builtin \ and \ operators in scala.xml
  • XML Schema validation, separate from parsing (validate a single element without having to serialize and re-parse)
  • Full support for XPath 1.0 [selections](XPath Selection)
  • Transformation rocks
  • Configurable canonicalization
  • String serialization and pretty-printing