I was discussing the requirements of a function that converts an XML to JSON and then back to XML.
Assuming I have the following XML and no XML schema:
<pets>
<pet1>dog</pet1>
<pet2>cat</pet2>
</pets>
In JSON an object is a set of unordered elements. Therefore both jsons are equal and would be a valid output of an xml2json converter.
{
"pets":
{
"pet1": "dog",
"pet2": "cat"
}
}
{
"pets":
{
"pet2": "cat",
"pet1": "dog"
}
}
Therefore when converting back from json to xml I might end up with
<pets>
<pet2>cat</pet2>
<pet1>dog</pet1>
</pets>
I only found this questions but they ask for elements of the same type. Therefore, I have some questions.
- Are both XML documents to be considered equal?
- Is there any authoritative source regarding the order of elements in xml?
- Would a DOM handle both XML documents as equal?