[CLOSED] Advanced XML / JSON Reader

  1. #1

    [CLOSED] Advanced XML / JSON Reader

    Hi all,
    i'm developing a WebService that retrives me data from a database using custom WebMethods.
    Now i want bind a ext:GridPanel with the data that a WebMethod retrives.
    The main problem is that the XML that my WebService serialize is a little bit more complex than the classical xml styles i saw in the coolite examples explorer.
    I post you an example saw here:
    <A href="https://examples1.ext.net/#/GridPanel/Miscellaneous/Xml_File_Loading/">
    https://examples1.ext.net/#/GridPane..._File_Loading/
    </A>
    As you can see the Plants.xml binded to the ext:GridPanel is not really so complex, in fact the xml structure is something like:

    <catalog>
      <plant>
        <common>Bloodroot</common>
        <botanical>Sanguinaria canadensis</botanical>
        <zone>4</zone>
        <colorCode>E7E7E7</colorCode>
        <light>Mostly Shady</light>
        <price>2.44</price>
        <availability>03/15/2006</availability>
        <indoor>true</indoor>
      </plant>
      <plant>
      ....
      </plant>
    </catalog>
    But what if the Plants.xml structure would be something like
    <catalog>
      <plant referenceKey="ADF63-A" price="2.44" colorCode="E7E7E7">
        <availability>03/15/2006</availability>
        <indoor>true</indoor>
        <zoneList>
            <zone>
                <id>5</id>
                <name>Europe</name>
            <zone>
            <zone>
                <id>3</id>
                <name>America</name>
            <zone>
        </zoneList>
      </plant>
      <plant>
      ....
      </plant>
    </catalog>
    How could i bind my ext:GridPanel with this xml mapping the attributes and childs of my Plant element?
    There is a way to map those fields on my XmlReader with something like this:

    <ext:Store runat="server" ID="Store1" AutoLoad="true">         
        <Proxy>
            <ext:HttpProxy runat="server" Url="../../Shared/Plants.xml" />
        </Proxy>
         <Reader>
                <ext:XmlReader Record="plant">
                    <Fields>
                        <ext:RecordField Name="plant.price" Type="Float" />
                        <ext:RecordField Name="plant.referenceKey" Type="String" />
                        <ext:RecordField Name="plant.zoneList.zone[0].name" Type="String" />
                    </Fields>
                </ext:XmlReader>
          </Reader>
    </ext:Store>
    I think this is impossibile to do but there's another way to do it with a XmlReader or JSON reader?

    Please Help,
    thanks in advice,

  2. #2

    RE: [CLOSED] Advanced XML / JSON Reader

    Hi,

    You can use XPath expression in Mapping property of RecordField. Unfortunately, it seems ExtJS parser does not understand standard XPath index expression therefore I set id for zone and attribute comparating instead getting by index

    XML
    <?xml version="1.0" encoding="utf-8"?>
        <catalog>
            <plant referenceKey="ADF63-A" price="2.44" colorCode="E7E7E7">
                <availability>03/15/2006</availability>
                <indoor>true</indoor>
                <zoneList>
                    <zone id="1">
                        <id>5</id>
                        <name>Europe</name>
                        <zone>
                            <zone>
                                <id>3</id>
                                <name>America</name>
                            </zone>
                        </zone>
                    </zone>
                    <zone id="2">
                        <id>6</id>
                        <name>Europe1</name>
                        <zone>
                            <zone>
                                <id>3</id>
                                <name>America</name>
                            </zone>
                        </zone>
                    </zone>
               </zoneList>
            </plant>
        </catalog>
    Store which reads this XML
    <ext:Store runat="server" ID="Store1" AutoLoad="true">
            <Proxy>
                <ext:HttpProxy runat="server" Url="Plants.xml" />
            </Proxy>
            <Reader>
                <ext:XmlReader Record="plant">
                    <Fields>
                        <ext:RecordField Name="referenceKey" Mapping="@referenceKey" />
                        <ext:RecordField Name="colorCode" Mapping="@colorCode" />
                        <ext:RecordField Name="price" Mapping="@price" Type="Float" />
                        <ext:RecordField Name="availability" Type="Date" />
                        <ext:RecordField Name="indoor" Type="Boolean" />
                        <ext:RecordField Name="zoneName" Mapping="zoneList/zone[id=1]/name"></ext:RecordField>
                    </Fields>
                </ext:XmlReader>
            </Reader>
        </ext:Store>
  3. #3

    RE: [CLOSED] Advanced XML / JSON Reader



    Hi Vladsh,
    that solution "open me a lot of doors".
    It works and it's a perfect solution!
    I could not ask for even better!

    Thanks again for your speed and complete solution,


  4. #4

    RE: [CLOSED] Advanced XML / JSON Reader

    Hi!
    How to write mapping to access parent node? In your sample from 'zone' node to 'indoor' node? I tried '../../indoor' but it isn't appear to work...
    regards

    Mrozik
  5. #5

    RE: [CLOSED] Advanced XML / JSON Reader

    Hi,

    Please create new topic and provide more details. What you try to accomplish? Parent node for mapping is Record (plant) therefore you cannot use '..'
  6. #6

    RE: [CLOSED] Advanced XML / JSON Reader

    OK - I explained problem in http://forums.ext.net/showthread.php...7206-16-1.aspx
    Mrozik

Similar Threads

  1. Replies: 4
    Last Post: Mar 20, 2012, 1:27 PM
  2. [CLOSED] Advanced StatusBar Example
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 15, 2010, 3:58 PM
  3. Advanced TabPanel
    By sachin.munot in forum 1.x Help
    Replies: 1
    Last Post: May 31, 2010, 1:16 AM
  4. Json reader not retrive all pages of data in grid panel
    By Satyanarayana murthy in forum 1.x Help
    Replies: 0
    Last Post: Dec 05, 2009, 4:58 AM
  5. [CLOSED] Passing JSON to Reader
    By Ben in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 02, 2008, 1:38 PM

Posting Permissions