Sunday, January 11, 2009

XML attribute value normalization

A couple of days back I was debugging a failed test case which was testing an XML generated by a Servlet. We were using JDom for generating the XML, and XMLUnit for testing. Testing involved comparing the generated XML with an XML on disk.

The test case was failing on a '\n' character in one of the attributes of the generated XML. The XML generated by the Servlet was something like this:

<root att="test \n value">

but JDom seemed to be putting some strange characters in place of '\n'

Now I had absolutely no idea about this, but the XML specification has something called "XML attribute normalization". Among other things, while adhering to this specification, JDom replaces all '\n' with Look here for more details.

The moment I replaced the '\n' in the expected data, the test worked like a charm.

No comments: