Package org.wamblee.xml

Utilities for XML processing.

See:
          Description

Interface Summary
XMLProcessor Generic XML processor.
XMLTextProcessor Represents an XML Processor that processes an XML file into text.
 

Class Summary
ClasspathUriResolver URI resolver that resolves stylesheets through the classpath.
DomUtils Some basic XML utilities for common reoccuring tasks for DOM documents.
SimpleNamespaceContext Implementation of NamespaceContext for binding namespace prefixes to namespaces.
XMLDocument Convenience class for representing an XML document.
XMLSchema Represents an XML Schema.
XPathContext Represents a namespace context and is a factory for creating xpath expressions.
XPathExpression XPath expression.
XSLTransformation Represents an XSL Transformation.
 

Exception Summary
XMLException Exception thrown in case of XML parsing problems.
 

Package org.wamblee.xml Description

Utilities for XML processing. The aim of this package is to simplify the common tasks of parsing, validating, and transforming XML files and to provide support for XPath. The utlities use the standard Java SE APIs but are much easier to use. For cases where more advanced functionality is required, the classes provide access to the underlying Java SE types. The implementation is based on DOM level 3 parsing.

Classes XMLDocument, XMLSchema, and XSLTransformation provide parsing, validation, and transformation of XML files. The XMLDocument class provides various static methods as entry point for this functionality, simplifying the code a lot when static imports are used. The API design uses a fluent interfaces style. For instance, to parse, validate, and transform an XML file, one can write:

 import static org.wamblee.xml.XMLDocument.*;
 ...
 XMLDocument doc = xmldocument(new File("x.xml").toURI()).validate(new File("x.xsd").toURI()).transform(new File("x.xsl").toURI());
 

In addition, a URI resolver ClasspathUriResolver is provided to allow resolution of documents on the classpath.

For XPath the following classes are provided:

For instance to apply an XPath expression to an XML document:

      NamespaceContext context = new XPathContext(new SimpleNamespaceContext()
            .addPrefix("n", "http://example.com/1")
            .addPrefix("m", "http://example.com/2"));
      XMLDocument doc = new XMLDocument(new File("xpathexample.xml").toURI());
      String value = context.createExpression("/n:root/m:x").stringEval(doc);
 

Or, using static imports:

      NamespaceContext context = xpathcontext(namespaces()
            .addPrefix("n", "http://example.com/1")
            .addPrefix("m", "http://example.com/2"));
      XMLDocument doc = xmldocument(new File("xpathexample.xml").toURI());
      String value = context.createExpression("/n:root/m:x").stringEval(doc);
 



Copyright © 2021. All Rights Reserved.