PDA

View Full Version : Suggested XML to JSON converter for tree use?



bschuhma
14 Aug 2008, 10:00 AM
I've been playing with XML to JSON code I've found here and there on the 'Net. Nothing produces JSON code suitable for a tree - seems the "standard" isn't so standard.

All my data is generated in a J2EE app as XML and I can't install a web server, so most of the standard methods of creating tree data are out for me (XMLReader requires XmlHTTPRequest and therefore a web server. So, too, does JSONReader).

Short of recoding the XML generator to return tree appropriate JSON, do you have, or can you suggest, an XML->JSON converter suitable for a tree?

Thanks!

Bret

NoahK17
14 Aug 2008, 10:45 AM
Google.com
Search phrase: "convert xml to json"
First link: http://goessner.net/download/prj/jsonxml/
Second link: http://www.thomasfrank.se/xml_to_json.html

Bah-da-boom.

bschuhma
14 Aug 2008, 11:01 AM
Thanks, Noah, but those are the two I've already tried. Do you have direct experience with them? Have you converted data from xml to a JSON string suitable for use with a tree? I found that one didn't create proper children arrays, the other mangled the elements a bit.

Bret

NoahK17
14 Aug 2008, 11:25 AM
Use the 2nd link, show us some examples. What's your XML data look like? Isn't there an XML tree loader anyways? I've always used JSON given to me by a PHP or Perl script.

bschuhma
14 Aug 2008, 12:02 PM
Here's a short excerpt of my much larger XML:

<?xml version="1.0" encoding="UTF-8"?>
<children text="TAC Net" dn="OU=TAC Net,DC=foobarbaz,DC=com">
<children text="Broker Voting System" dn="OU=Broker VotingSystem,OU=TACNet,DC=foobarbaz,DC=com">
<children text="Broker Vote" dn="OU=Broker Vote,OU=Broker Voting System,OU=TAC Net,DC=foobarbaz,DC=com"/>
</children>
</children>

Here's what the web site returned:



{
children:{
text:'TAC Net',
dn:'OU=TAC Net,DC=foobarbaz,DC=com',
children:{
text:'Broker Voting System',
dn:'OU=Broker VotingSystem,OU=TACNet,DC=foobarbaz,DC=com',
children:{
text:'Broker Vote',
dn:'OU=Broker Vote,OU=Broker Voting System,OU=TAC Net,DC=foobarbaz,DC=com'
}
}
}
}
And here's what the tree requires:


[{
text:'TAC Net',
dn:'OU=TAC Net,DC=foobarbaz,DC=com',
children:[{
text:'Broker Voting System',
dn:'OU=Broker VotingSystem,OU=TACNet,DC=foobarbaz,DC=com',
children:[{
text:'Broker Vote',
dn:'OU=Broker Vote,OU=Broker Voting System,OU=TAC Net,DC=foobarbaz,DC=com'
}]
}]
}]
Note all the extra square brackets to tell the tree things are arrays - even single element arrays must be enclosed in brackets. The Java code from json.org doesn't even put brackets around single element arrays, but Ext trees expect them :-(.

I can't use an XMLReader or TreeReader because (I *believe*) they will require XMLHTTPRequest, which requires a web server. I *can't* install a web server, so I have to have a static way to load a tree from XML or JSON.


Rgds,

Bret

bschuhma
15 Aug 2008, 7:26 AM
Bueller? Bueller? Anyone have thoughts or workarounds how I can take standard JSON output and feed it to a tree? I'm about to start hacking the json.org java files to produce Ext compatible JSON data, but I'd rather not go that route.

Can the Ext tree be made more lenient, with respect to how it handles properly formatted JSON data?

Thanks,

Bret

carol.ext
15 Aug 2008, 8:47 AM
All my data is generated in a J2EE app as XML and I can't install a web server, so most of the standard methods of creating tree data are out for me (XMLReader requires XmlHTTPRequest and therefore a web server. So, too, does JSONReader).


So, how do you get your xml? I'm curious because I'm thinking most J2EE apps are running on an application server that is also a web server.