Google Answers Logo
View Question
 
Q: XML to JSON using PHP ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: XML to JSON using PHP
Category: Computers > Internet
Asked by: goose_man-ga
List Price: $2.00
Posted: 11 Jul 2006 02:29 PDT
Expires: 10 Aug 2006 02:29 PDT
Question ID: 745221
Hi,

Just wondering what the best way to go from XML to JSON is?

I have tried to find a good XSLT that can do this, but so far no luck.
Maybe there is a better way of doing this?

Appreciate any advice,

Thanks!
Answer  
Subject: Re: XML to JSON using PHP
Answered By: eiffel-ga on 11 Jul 2006 03:19 PDT
Rated:5 out of 5 stars
 
Hi goose_man-ga,

If you don't want to use an XSLT approach such as json-xslt from
eBay's Community Codebase
https://json-xslt.codebase.ebay.com/
then you could consider BadgerFish:

   BadgerFish
   http://badgerfish.ning.com/

BadgerFish is a set of conventions for how XML data should be
represented in JSON. If you are able to use these convention for your
application, it makes processing and conversion rather
straightforward. BadgerFish also includes a PHP class to do the
conversion from an XML document to the JSON string (formatted
according to BadgerFish conversion conventions) - see the "How Can I
Use It" section of the BadgerFish web page.

I trust you find this approach useful. It's certainly the approach I
would use for this purpose.

Regards,
eiffel-ga


Google Search Strategy:

"xml to OR 2 json" php
://www.google.com/search?q=%22xml+to+OR+2+json%22+php

Request for Answer Clarification by goose_man-ga on 11 Jul 2006 05:21 PDT
Ah - I looked at the ebay solution:

My issue there was:

I have been using ebayxslt to get results to a JSON format. However,
this is limited to the one search command. To use the full range of
XML queries, I have had to resort to using a XSLT conversion to the
XML returned output.

I have used the XSL file provided here, but the importstyleSheet
conversion is different to the ebayxslt implementation. For example:

ebay XSLT:

... { "BuyingGuideHub": "http://search.reviews.ebay.com/widgets_W0QQuqtZg" }] } }

[WORKS WITH WHAT I WROTE]]

importstyleSheet:

... { "BuyingGuideHub":
"http://search.reviews.ebay.com/widgets_W0QQuqtZg" } , { }] , } }

[DOES NOT WORK WITH WHAT I WROTE]

Any idea how to solve this?

Clarification of Answer by eiffel-ga on 11 Jul 2006 08:12 PDT
Hi goose_man-ga,

The output from your "importstyleSheet" conversion is not valid JSON
because it contains an empty unnamed member, according to the JSON
grammar on the following page:

   Introducing JSON
   http://www.json.org/

Unfortunately I do not have the experience to debug the XSLT
stylesheet. If you want to pursue the XSLT approach further, you may
wish to post a new question for another researcher to attempt.

I'm glad you found the link to BadgerFish useful.

Regards,
eiffel-ga
goose_man-ga rated this answer:5 out of 5 stars
Thanks for the BadgerFish link!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy