[SOLVED] Advanced XML / JSON Reader
New Community Forums available at http://forums.ext.net
 

Coolite Forums

Welcome Guest ( Login | Register )
 
[SOLVED] Advanced XML / JSON Reader
Subscribe
Last Login: 9/30/2009 3:04:08 PM
Posts: 64,
Posted 5/19/2009 4:58:16 AM

Group: Coolite Premium Member & Early Adopter
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:

http://examples.coolite.com/?/GridPanel/Miscellaneous/Xml_File_Loading/

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,

Andrea Cammarata


www.immobilmente.com

www.andreacammarata.com

Last Login: 7/5/2010 10:10:13 AM
Posts: 7,853,
Posted 5/19/2009 6:01:20 AM

Group: Core Development Team
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>


--
Vladimir Shcheglov
Coolite Inc.
Development Team
Forum Guidelines | Coolite Examples | Coolite API Docs | ExtJS API Docs | Twitter
Last Login: 9/30/2009 3:04:08 PM
Posts: 64,
Posted 5/19/2009 6:29:19 AM

Group: Coolite Premium Member & Early Adopter

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,


Andrea Cammarata


www.immobilmente.com

www.andreacammarata.com

Last Login: 5/25/2010 8:08:04 AM
Posts: 53,
Posted 2/8/2010 2:02:12 PM

Group: Coolite Premium Member & Early Adopter
 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

Mrozik
---------------------
Sapico Sp. j.
http://www.sapico.pl
Last Login: 7/5/2010 10:10:13 AM
Posts: 7,853,
Posted 2/9/2010 1:35:01 AM

Group: Core Development Team
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 '..'

--
Vladimir Shcheglov
Coolite Inc.
Development Team
Forum Guidelines | Coolite Examples | Coolite API Docs | ExtJS API Docs | Twitter
Last Login: 5/25/2010 8:08:04 AM
Posts: 53,
Posted 2/9/2010 1:53:05 AM

Group: Coolite Premium Member & Early Adopter
 OK - I explained problem in http://www.coolite.com/forums/Topic27206-16-1.aspx
Mrozik

Mrozik
---------------------
Sapico Sp. j.
http://www.sapico.pl
« Prev Topic | Next Topic »
Reading This Topic
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.
All times are GMT -5:00, Time now is 4:46pm