PDA

View Full Version : parsing nested XML: xml reader



dikshyant.pradhan
11 Aug 2012, 5:37 PM
Hi
I have an Xml response from server like,

<properties>
<property id=”123” name=”p1”>


<value name=”v1” attrb1=”12” />
<value name=”v3” attrb1=”12” />
<value name=”v4” attrb1=”12” />


</property>


<property id=”13” name=”p2”>


<value name=”v2” attrb1=”12” />

</property>

<properties>

I understand that using 'hasMany' config I can store the xml data into two models (say, Property & Value),only if the value elements are inside a <values> </values> tag. For example,

<property id=”123” name=”p1”>
<values>


<value name=”v1” attrb1=”12” />
<value name=”v3” attrb1=”12” />
<value name=”v4” attrb1=”12” />


</values>

</property>

But, my server response doesn't have this <values> tag and I can't modify the server response. Is there any way I can read my server response using xml reader?? or can i parse my xml response somehow OR modify it on client side before reading ??

Any help is appreciated... Thanks

mrsunshine
13 Aug 2012, 7:39 AM
You can define a mapping from XML structure path to model field see:

http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Field-cfg-mapping

dikshyant.pradhan
13 Aug 2012, 8:17 PM
Hi Thanks for replying.. But how can i map multiple records of that model to a specific record ? Could you specify an example.. Thanks again..

jordandev
11 Jul 2013, 12:34 PM
I am also wondering this.


There doesn't seem to be anyway to get the hasMany association to get all of the <value> elements without having a <values> parent.


Seems like an oversight in the XML reader to me.

koujiid
2 Sep 2013, 8:54 AM
I have the same problem.

So, if respons xml file format had the some bottom node with same name , I can't get the node value.
If I set the bottom node to record config , I can't get the value.
If I set the next bottom node to record config , I get the only one bottom node value.

Is there the solution?:-/

Example: I can't get the LastNode value with xmlreader.

<Node1>
<Node2>
<LastNode>1</LastNode>
<LastNode>2</LastNode>
<LastNode>3</LastNode>
<LastNode>4</LastNode>
<LastNode>5</LastNode>
<LastNode>6</LastNode>
<LastNode>7</LastNode>
<LastNode>8</LastNode>
</Node2>
</Node1>

Thank you.