Reputation: 11
XML response is like this:
<?xml version="1.0"?>
<Response xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ReturnCode>525</ReturnCode>
<ReturnMessage>Coupon maximum usage limit reached.</ReturnMessage>
</Response>
JSON response is like this:
{"Response":{"@xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
"@xmlns:xsd":"http://www.w3.org/2001/XMLSchema",
"ReturnCode":"429",
"ReturnMessage":"Invalid Coupon offer code"}}
Question: How can I compare and determine whether these two are same without converting?
Upvotes: 1
Views: 41
Reputation: 111686
XML and JSON are mere data formats. Comparison implies a basis, typically a semantic one, so the general answer to your question is no, you cannot tell whether two arbitrary XML and JSON messages mean the same.
In any particular case, however, one might assume that similarly named data ought to have the same values. In your case, your XML sample has data ReturnCode
with a value of 525, yet your JSON has data ReturnCode
of 429. Therefore, it'd be reasonable to assume that your XML and your JSON are not the same.
Upvotes: 4