[CLOSED] Using XML instead of JSON

  1. #1

    [CLOSED] Using XML instead of JSON

    Hello

    We are trying to rewrite one of our very old backed application using Ext UI frontend
    Now the problem is that old backend communicate only in XML

    example

    on input of the form editing ( basically load of the form) I get

    <RESPONSE >
    	<DOCUMENT OBJECTID="37819" VERSIONSTAMP="71828096" VERSION="0.1">
    		<DOCNAME ISDIRTY="false" GDNFORMAT="">asd</DOCNAME>
    		<DOCTITLE ISDIRTY="false">Test1Doc2003</DOCTITLE>
    	</DOCUMENT>	
    </RESPONSE>
    and when sending reply back ( esentially saving form) I'm supposed to send the same XML, with ISDIRTY attributes set to true, where value has been changed. I have to send complete XML, so for example if DOCNAME has changed and DOCTITLE not, I'm supposed to send

    <RESPONSE >
    	<DOCUMENT OBJECTID="37819" VERSIONSTAMP="71828096" VERSION="0.1">
    		<DOCNAME ISDIRTY="true" GDNFORMAT="">new name</DOCNAME>
    		<DOCTITLE ISDIRTY="false">Test1Doc2003</DOCTITLE>
    	</DOCUMENT>	
    </RESPONSE>
    The xml is seriously long and whole system contains dozens of such forms
    Now the question on very generic level. How to approach app like that? On of obvious ways is to Convert XML on JSON on some level above old backed, sent to js, send back, compose xml and pass to old backed back. Howerer is there a way how to avoid XL to JSON conversions? I'm asking especially because of developper productivity.
    I Check XmlStore, MVVM in sencha, I haven't found anything realy helpful. Idea is to write some kind of XmlReader/Writer (Extjs class), that would get XPath and bind directly to UI field. On writing add ISDIRTY attributes

    Any hint or kick to the righ direction?

    Thanks
    Zdenek
    Last edited by fabricio.murta; Oct 29, 2016 at 9:06 PM. Reason: no user feedback for 7+ days
  2. #2
    Hello @Zdenek!

    I'm not sure you should worry much with that. At least according to the following question in stackoverflow, you should be able to make a generic wrapper to convert, from server side, the XML <==> Json transparent between the legacy application and the new frontend.

    Actually, with Ext.NET you can just load the XML into an object and return that object, Ext.NET does the serialization and deserialization for you.

    Related stackoverflow question: c# - Convert JSON to XML or XML to JSON

    Also, browse our examples explorer, and filter examples with the word XML, you'll find some examples based on XML data format that might be just what you want.

    This example may be particularly useful in alternatives too: GridPanel - Paging - Data from a XML Web Service

    In the next example, you can see that just a simple object is returned. If you map -- server-side -- the XML data using C# facilities/libraries to an object you can do just like same, and even better if you have a fast connection from the server to the XML legacy web service to make the conversions: Simple array Grid Panel

    I hope some of these ideas help!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    OK
    So if I start with your samples, there are following problems

    if I take this xml

    <RESPONSE >
    	<DOCUMENT OBJECTID="37819" VERSIONSTAMP="71828096" VERSION="0.1">
    		<DOCNAME ISDIRTY="false" GDNFORMAT="">asd</DOCNAME>
    		<DOCTITLE ISDIRTY="false">Test1Doc2003</DOCTITLE>
    	</DOCUMENT>	
    </RESPONSE>
    And now I want to display Version, DocName and DocTitle, how can I do that?
    XmlReader allows me to specify Record (and RootProperty if required) but how to tell that Version should be taken from attribute and DocName from tag value?

    Using wrapper C# object - that's way I know tht exists. But one I trie to avoid. Note that xml is really complex, about half of attributes is required to be used on UI, but as I must to pass full xml back to the save methods, I need to map all properties (even ones I do not need on user interface), so that's why I'm trying to find any other option. Idea is to bind somehow possibly using ExtJs MVVM directly to XML

    Thanks
    Zdenek
  4. #4
    Hello @Zdenek!

    You'll have to specify in the XML reader, for each node attribute you want, a mapping for the field. And using the selector appropriately might be challenging. See this Sencha thread, for example: Can't get at xml attribute with XMLReader maybe causing paging toolbar not to work.

    As for a general reader/responder, I'm afraid it will not really work, as it will only be extracting node attributes you explicitly map out.

    Here's a JavaScript console example for you to try making the right selector to get the attribute you want:

    var xmlD='    <RESPONSE > ' +
    '	<DOCUMENT OBJECTID="37819" VERSIONSTAMP="71828096" VERSION="0.1">' +
    '		<DOCNAME ISDIRTY="false" GDNFORMAT="">asd</DOCNAME>' +
    '		<DOCTITLE ISDIRTY="false">Test1Doc2003</DOCTITLE>' +
    '	</DOCUMENT>	' +
    '</RESPONSE>';
    
    var domobj = (new DOMParser()).parseFromString(xmlD, 'text/xml');
    Ext.DomQuery.selectValue("/DOCUMENT/@VERSION", domobj.documentElement);
    Hope this helps you deciding the best approach to take in your scenario!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello again, @Zdenek!

    We didn't hear back from you for some days now. Do you still need assistance with the issue? We'll wait another week for your feedback before marking this thread as closed. But you can post follow ups anytime.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Using JSON.Serialize() and JSON.Deserialize()
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Apr 30, 2013, 2:37 PM
  2. [CLOSED] Json 4.0
    By majunior in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 24, 2011, 6:32 PM
  3. Get json in codebehind.
    By luiz in forum 1.x Help
    Replies: 0
    Last Post: Apr 19, 2011, 4:14 PM
  4. How to select row by JSon...
    By rebulanyum in forum 1.x Help
    Replies: 0
    Last Post: Mar 03, 2010, 5:29 AM

Posting Permissions