1. | What's the difference between XOM and JDOM? |
XOM and JDOM are completely separate products.
Originally, I had thought I could build XOM by forking JDOM,
but it quickly became apparent that it would be simpler to start over from scratch.
Some early versions of XOM did use one class
from JDOM ( Conceptually, XOM definitely did adopt a number of ideas from JDOM, including:
However, XOM also freely borrowed good ideas from DOM, XPath, and other systems, and invented not a few new ones of its own. Features in XOM that have no real equivalent in JDOM include:
There are also many features that JDOM and XOM share, but that are implemented very differently in the two APIs:
Finally, XOM hews closely to the motto that “Less is more.”
It deliberately eschews the many convenience methods that make the JDOM
API so cluttered such as
| |
2. | Does XOM support XML 1.1? |
No. XML 1.1 is an abomination. You don't need it and you shouldn't use it. In general, XOM focuses on giving developers what they need instead of what they think they want. XOM 1.0 through 1.3 will not support XML 1.1. Possible future versions might, provided someone can demonstrate an actual need for it. The following are not legitimate needs:
You just might convince me you have a legitimate need for C0 control characters, but I doubt it. That still leaves a couple of possible uses for XML 1.1, but they're very obscure. (Do you speak Burmese?) Note that a hypothetical use-case is not going to do it. You're going to have to show me that you actually need to do this, and that you are going to use XOM. | |
3. | Can I make XOM smaller? |
Yes. All you really need is the xom.jar file. This contains all the core packages, but not the samples or unit tests. It has no dependencies besides JDK 1.6 or later. If you want to trim XOM down even further, you can remove some of the non-core packages. All you really must have is in the nu.xom package. nu.xom.xslt, nu.xom.canonical, nu.xom.xinclude, and nu.xom.converters are only needed if you want their functionality. Nothing in the core nu.xom package depends on them. | |
4. | Can I make XOM faster? |
There are a number of techniques you can use to speed up your XOM programs. Among them:
As a last resort, the | |
5. | Can I make XOM use less memory? |
Yes. If your documents are so large that you're running out of memory,
you can use a custom
If the document you've built is still too large to handle, then you can try processing in streaming mode inside the | |
6. | Will XOM run with Java 1.1? 1.2? 1.3? 1.4? 1.5? 1.6? 1.7? 1.8? 9? 11? 17? 21? 25? |
XOM 1.3.x requires Java 1.6 or later. Earlier versions required 1.2 or later. XOM has been updated to work with modern Java versions including Java 9+ with support for the Java Platform Module System. XOM 1.3.7 eliminated usage of com.sun classes to ensure compatibility with JDK 16 and later. XOM 1.3.8 includes internal changes for compatibility with Java 17+. | |
7. | Isn't the LGPL incompatible with Java? Can I have a different license? |
You should learn better than to believe everything you read on Slashdot. The LGPL is completely compatible with Java. Claims that it is not are based on severe misunderstandings of either Java, the LGPL, or both. The official word from the FSF's David Turner is,
If you would like a license to use XOM under other conditions, feel free to make me an offer. Non-LGPL, closed source licenses are available for a reasonable fee. | |
8. | How is nu.xom pronounced? |
Like “new dot zom”. | |
9. | Does this have anything to do with Omnimark? |
No. I had no idea that the three letter extension for Omnimark files
was | |
10. | Why doesn't XOM implement the Visitor pattern? |
I'm familiar with the visitor pattern. I did explore it when
I was first designing XOM. I'm still not convinced it really fits
the XML problem space well. I don't like adding the extra method to
Or at least I agree until someone shows me how much easier visitor would make important operations. It's also a question of programmer familiarity. I think Visitor is one of those issues like interfaces vs. classes, push vs. pull, and pointers vs. stack variables, where the more advanced solution may be marginally better and more extensible for some uses, but really exceeds a lot of working programmers' comfort level. The level of abstraction and indirection can just get too high. Putting the client more in control is a lot more comfortable for most programmers since they can more easily see and visualize how the code flows. I am willing to trade some level of extensibility and generality in exchange for simplicity. | |
11. | How can I validate against a schema in XOM? |
XOM does not have built-in support for schema validation.
However, you can use a schema-validating SAX
String url = "http://www.example.com/";
try {
XMLReader xerces = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
xerces.setFeature("http://apache.org/xml/features/validation/schema", true);
Builder parser = new Builder(xerces, true);
parser.build(url);
System.out.println(url + " is schema valid.");
}
catch (SAXException ex) {
System.out.println("Could not load Xerces.");
System.out.println(ex.getMessage());
}
catch (ParsingException ex) {
System.out.println(args[0] + " is not schema valid.");
System.out.println(ex.getMessage());
System.out.println(" at line " + ex.getLineNumber()
+ ", column " + ex.getColumnNumber());
}
catch (IOException ex) {
System.out.println("Due to an IOException, Xerces could not check " + url);
} | |
12. | Why do some of the unit tests fail when building XOM? |
There are two known failures that arise in some environments and not others.
Several of the tests in
Roughly seven integration tests including | |
13. | Why does xsl:output have no effect when transforming with XOM? |
xsl:output has no relevance to tree construction, only to the serialization of the result tree as text. Since XOM's XSLT constructs a result tree, but does not serialize it, xsl:output has no effect.
You can set any necessary serialization options directly on the | |
14. | How do I find all the namespaces in scope on an element? |
Use XPath. Specifically use the query Nodes namespaces = element.query("namespace::node()"); | |
15. | How do I protect against the billion laughs (XML entity expansion) attack? |
The billion laughs attack
(also known as an XML bomb or exponential entity expansion attack) exploits deeply nested
XML entity references to cause the parser to consume an excessive amount of memory.
To protect against this, configure the underlying SAX parser to enable
JAXP secure processing
before passing it to XOM's XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
Builder builder = new Builder(reader);
JAXP secure processing limits entity expansion (to 64,000 by default in most implementations).
If you are using Xerces directly, you can also control this limit via the
XMLReader reader = XMLReaderFactory.createXMLReader(
"org.apache.xerces.parsers.SAXParser");
reader.setProperty(
"http://apache.org/xml/properties/security-manager",
new org.apache.xerces.util.SecurityManager());
Builder builder = new Builder(reader); |