I've been working on bringing Android's DOM implementation up to version 3. This process has exposed me to some ugly code. For your entertainment, here are the worst bits:
-
DocumentBuilder.parse() doesn't accept references to unparsed entities. But you can build such a DOM programatically.
-
The API doesn't specify whether entity references will be expanded at parse time. To be sure, both the parser and its client need to have code that implements entity expansion.
-
Node.setTextContent("foo") silently does nothing for certain node types.
-
Node.lookupNamespaceURI(null) disagrees with isDefaultNamespace(String) for certain node types.
-
[Node.getFeature()](http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html#getFeature(java.lang.String, java.lang.String)) forces users to map Strings to Java types. Type safety by fortune!
-
The API bends over backwards to allow competing implementations to interoperate. For example, Node.compareDocumentPosition() throws when_ "the compared nodes are from different DOM implementations that do not coordinate to return consistent implementation-specific results."_ Who does this?
-
The Javadoc from UserDataHandler.NODE_DELETED: "This may not be supported or may not be reliable in certain environments, such as Java, where the implementation has no real control over when objects are actually deleted." It says this in Javadoc!
I parse XML so you don't have to.