Print

Print


If PHP/python isn't a hard requirement, I think this would be fairly
simple to do in perl using a combination of the XML::Simple [1] and
JSON::XS [2] modules.

In fact it's so simple, here's the code:

"""
#!/usr/bin/perl

use JSON::XS;
use XML::Simple;
use strict;

my $filename = shift @ARGV;
my $parsed = XMLin($filename);
my $json = encode_json($parsed);
print $json, "\n";
"""

XML::Simple, in spite of the name, actually allows for a myriad of
options for how the perl data structure gets created from the xml,
including attribute preservation, grouping of elements, etc.

--jay

[1] http://search.cpan.org/~grantm/XML-Simple-2.18/lib/XML/Simple.pm
[2] http://search.cpan.org/~makamaka/JSON-2.17/lib/JSON.pm

On Fri, Mar 5, 2010 at 9:55 AM, Joe Hourcle
<[log in to unmask]> wrote:
> On Fri, 5 Mar 2010, Godmar Back wrote:
>
>> On Fri, Mar 5, 2010 at 3:59 AM, Ulrich Schaefer
>> <[log in to unmask]>wrote:
>>
>>> Hi,
>>> try this: http://code.google.com/p/xml2json-xslt/
>>>
>>>
>> I should have mentioned that I already tried everything I could find after
>> googling - this stylesheet doesn't meet the requirements, not by far. It
>> drops attributes just like simplexml_json does.
>>
>> The one thing I didn't try is a program called 'BadgerFish.php' which I
>> couldn't locate - Google once indexed it at badgerfish.ning.com
>
>        http://web.archive.org/web/20080216200903/http://badgerfish.ning.com/
>
>  http://web.archive.org/web/20071013052842/badgerfish.ning.com/file.php?format=src&path=lib/BadgerFish.php
>
> -Joe
>