Jonathan Britt
Jonathan Britt

Reputation: 53

How can I tell if my XML has been correctly parsed to JSON?

I've been working on a project lately and decided to take a crack at JSON instead of using XSLT stylesheets.

I am trying to use the Fyneworks XML --> JSON plugin in convert my XML file loaded via Ajax.

How can I tell if this has been converted correctly so I can start parsing it.

Here is the HTML and Ajax call with jquery which i have tried so far.

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="jquery.xml2json.js"></script>
        </head>
    <body>
       <script type="text/javascript">
          $(document).ready(function(){
             $.ajax({
             type:"GET",
             url:"lou.xml",
             datatype:"xml",
             success: function(xml) {
            $.get('lou.xml',function(xml) {
                   var json=$.xml2json(xml);
                   alert(json.message); 
                     });
             }
              })
            });
      </script> 
    </body> 
</html>

Upvotes: 0

Views: 70

Answers (2)

Mike Lyons
Mike Lyons

Reputation: 1792

Take the JSON output, use another utility to convert it back into XML, then run a diff to see if it is identical to the original XML.

Upvotes: 1

Matthew Daumen
Matthew Daumen

Reputation: 851

If you have a schema for the xml doc you're working with you could validate the output against the schema.

Upvotes: 1

Related Questions