开发者

org.json.XML.toString() changes the order of the XML elements

I'm seeing that a parsed JSON object from a source XML that gets converted back into XML doesn't return the equivalent XML when I print it out to file. Is anyone else seeing this same isue?

I have a XML document that I'm able to easily parse into a json object using org.json.XML.java. Just for testing purposes I took my newly parsed JSONObject and reversed it back to开发者_如何学Go XML using org.json.XML.toString() and seeing the above results.

Any help is appreciated.


as per the spec XML attributes can be in any order, and as per the spec there is no order enforced on PEER elements. Search SO for more articles on this if you don't believe me, I have posted many times about this same issue here on SO.

<root a="a" b="b" c="c">
  <a/>
  <b/>
  <c/>
</root>

is just as valid as

<root c="c" a="a" b="b">
  <c/>
  <a/>
  <b/>
</root>

as per the spec

now application specific parsers may expect elements in certain a order, XHTML is an example of this, and that is ok, because it is application specific. But expecting attributes in a specific order is really wrong at any time. You don't post an example so we don't know for sure what you are referring to, but either way the spec is really loose, as in has nothing to say about peer element order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜