A few patches applied and a new version of XML::Writer released; what’s new?
- Allow scalar references for the OUTPUT parameter, inspired by Simon Oliver's XML::Writer::String (patch from Yanick Champoux)
Often, you want to generate XML and store it in a scalar, rather than directly in a file. XML::Writer expects an IO::Handle, and there are wrapper classes, but it’s not very Perlish to make users jump through type-safe hoops. You can now pass in a scalar reference instead, which will be used to store the generated XML document.
- Added ENCODING parameter; currently only UTF-8 is supported
As I’ve written before, it’s usually best to be explicit about character encoding. This parameter is just a way to say, yes, you understand Unicode and you want UTF-8 output. It changes the encoding of the underlying stream, and also sets the default encoding in the XML declaration. It wouldn’t be a stretch to support UTF-16 as well, but supporting anything that doesn’t encode the full Unicode repertoire means the escaping code need to be rewritten to use numeric references in certain cases.
- Escape newlines in attribute values
It’s fair to say that the rules for white space in XML are fairly complicated (misspelling “white space” as “whitespace”; how ironic). One user needed to include a newline in an attribute value; according to the spec for attribute value normalisation, the only form that survives this process is a numeric reference to the newline character. Now, any newlines in attribute values are escaped.