XMLSerialize ignores first element
Hey, I have a simple utility funct开发者_运维问答ion:
public static String xmlToJson() {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><account id=\"DEV55419669\"></account>";
XMLSerializer serializer = new XMLSerializer()
String result = serializer.read(xml).toString();
return result;
}
The result is:
{"@id":"DEV55419669"}
Any ideas why the XMLSerializer "drops" the first element?
p.s. - XMLSerializer is net.sf.json.xml.XMLSerializer.
Thanks, Udi
What first element?
If you're refering to the part starting with <?xml
, then the reason is simple:
It's not an XML element, but the header (formally it's called the XML declaration and is part of the prolog)
精彩评论