1. #1
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    10
    Vote Rating
    0
    optimalcapacity is on a distinguished road

      0  

    Default Convert XML Data to JSON Data

    Convert XML Data to JSON Data


    Hey everyone...

    I am new to ExtJS and am working on a demo which utilizes ExtJS on the front-end while the backend system is based on both J2EE and Java Servlet technology. The backend system has natively handled XML output for years. While ExtJS has many of the widgets needed for this demo, I still need a few extra UI components currently available from other libraries. These other libraries currently support JSON data formats. Does ExtJS natively support the conversion of XML data to JSON data? For the demo, I will have to juggle both XMl and JSON datasets. If so, could you please direct me to the necessary code or provide me with an example? If not, any ideas and all ideas are appreciated!

    I realize the best approach for this demo would be to add the server-side output of JSON. However, one of the objectives of this demo is to have legacy support for pre-existing solutions built on XML datasets. Once I can prove the effectiveness of ExtJS from the client-side, I can work on selling optimizations on the server-side to the business.

    Thanks in advance!

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    You will usually be reading Records into your client which are cached in Stores which provide the Model for the DataView and the GridPanel.

    You will use an XmlReader to convert the received XML data.

    There is full documentation in the API docs, there are examples in your examples directory, and there is lots of information in the grid FAQ.

    If you have any specific questions, someone will try to answer.

  3. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,943
    Vote Rating
    636
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    There's no native support for it. In fact it would probably be a whole lot quicker to do that conversion server side.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  4. #4
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    10
    Vote Rating
    0
    optimalcapacity is on a distinguished road

      0  

    Default


    Thanks for the quick replies!

    I agree that server-side generated JSON is preferred. However, for this demo, it really isn't an option.

    After digging around the ExtJS documentation and the forums, I thought the answer would be "no" but with it's built-in support of consuming both XML and JSON formats, I thought someone had to have had the need to convert between these formats and worked out a XML-JSON bridge.

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I don't think thwe OP means XML representation to JSON representation. I think the OP means XML representation to Javascript objects. He says "JSON data" which people usually use when they mean "an object".

    I don't see any use for converting one textual data interchange format into another on a client.

  6. #6
    Ext JS Premium Member vishalg's Avatar
    Join Date
    Sep 2007
    Location
    Los Angeles, CA
    Posts
    75
    Vote Rating
    0
    vishalg is on a distinguished road

      0  

    Default


    Here's a JavaScript library that can convert XML to JSON;

    http://www.thomasfrank.se/xml_to_json.html

    But this will not help in any of the Ext components.

  7. #7
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    10
    Vote Rating
    0
    optimalcapacity is on a distinguished road

      0  

    Default


    Thanks vishalg!

  8. #8
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    I'm not clear on why you would send out XML from a server, and convert to a JSON string on the client.

    Then where else would you send that string for further processing???

  9. #9
    Ext JS Premium Member
    Join Date
    Nov 2007
    Posts
    10
    Vote Rating
    0
    optimalcapacity is on a distinguished road

      0  

    Default


    The web application solution that I have been working with has been around for over 8 years. Up to this point, the native delivery format of data to the client has been XML. While I could easily add support for JSON data and move forward with this approach, the server-side implementation of JSON would require server-side architectural changes for existing customers solutions. The focus of my demo is to offer a client-side alternative to the existing product offering. This will only be successful if I can minimize the number of architectual impacts. In other words, a few extra lines of client-side code isn't as painful as both client and server required revisions.

    The issue that I am running into is that some of the JS libraries required for this demo will consume data in JSON data format only. So to minimize the number of requests to the server (and since ExtJS can consume XML or JSON data), I was curious to see if anyone has created a bridge between these data stores.

    Thanks!

  10. #10
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,506
    Vote Rating
    54
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    XmlReader?