Add support for adding attributes to output for root element (original) (raw)

(note: inspired by http://stackoverflow.com/questions/21086717/how-to-convert-pojo-to-xml-with-jackson)


It would make sense to be able to indicate that a specific XML Schema instance would be output as, say:

<TestUser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="testUser.xsd">

or

<TestUser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="testUserNoNs.xsd">

This should be done using new (in 3.2) XmlGeneratorInitializer, allowing arbitrary Attributes to be added to the root element, including XMLSchema-instance ones (but not just those): specifying:

  1. Attribute name as QName
  2. Attribute value as String

plus allowing String convenience overload for name (so 2 methods).

Attribute name/value combination to be stored as new RootAttribute value class which extends XmlGeneratorWritable.