Atom Feed SITE FEED   ADD TO GOOGLE READER

org.w3c.dom WTFs of the week

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() 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.