Etewa - 2009-06-12

I am trying to convert a simple HashMap<String, String> to an XML document.  The JSON conversion works fine, but the XML Conversion fails.

Map<String, String> data = new HashMap<String, String>();
data.put("1", "Hello");
data.put("2", "World");
JSONObject json = JSONObject.fromObject(data);

JSON Output
{"2":"World","1":"Hello"}

XML Output causing exception
new XMLSerializer().write(json);

Exception in thread "main" nu.xom.IllegalNameException: NCNames cannot start with the character 31
    at nu.xom.Verifier.throwIllegalNameException(Verifier.java:147)
    at nu.xom.Verifier.checkNCName(Verifier.java:126)
    at nu.xom.Element._setLocalName(Element.java:832)
    at nu.xom.Element.<init>(Element.java:111)
    at nu.xom.Element.<init>(Element.java:75)
    at net.sf.json.xml.XMLSerializer.newElement(XMLSerializer.java:869)
    at net.sf.json.xml.XMLSerializer.processJSONObject(XMLSerializer.java:989)
    at net.sf.json.xml.XMLSerializer.write(XMLSerializer.java:605)
    at net.sf.json.xml.XMLSerializer.write(XMLSerializer.java:570)
    at test.SMTSerializer.main(SMTSerializer.java:61)