PDA

View Full Version : XmlReader for Xml with multiple similar child nodes...



bzborow1
13 Jul 2010, 7:48 AM
Hi guys,

I'm building a simple extjs reader that connects to a j2EE web service and displays the results. My problem is I don't know how I can map the XmlReader where there are multiple child node instances. Example xml:



- (http://www.sencha.com/forum/) <result>
- (http://www.sencha.com/forum/) <attributes>
<attribute>Geometry type: 4</attribute>

<attribute>Exterior ring: 1</attribute>

<attribute>Point count: 5</attribute>

<attribute>Lambert_Conformal_Conic</attribute>

<attribute>85758</attribute>

<attribute>993f75ed-dfc0-4d84-8d95-29462313f331</attribute>

<attribute>morrisonb</attribute>

<attribute>Thu May 27 00:00:00 CST 2010</attribute>

<attribute>4</attribute>

</attributes>


- (http://www.sencha.com/forum/) <extent>
<minx>-480848.0771999992430210113525390625</minx>

<maxx>-479586.4708000011742115020751953125</maxx>

<miny>231779.4936999976634979248046875</miny>

<maxy>233042.39090000092983245849609375</maxy>

</extent>


</result>




And the javascript



Ext.onReady(function() {

//Create the data store.
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
method: 'GET',
disableCaching:true,
url:"http://localhost:8085/agmafWSCplSearch/rest/attributeSearch?attr=township&attrv=16&attr=range&attrv=14&attr=meridian&attrv=w1&attr=section&attrv=10"
}),
reader: new Ext.data.XmlReader({
record: 'result'
},[
{name: 'SR', mapping: 'attributes > attribute[1]'},
{name: 'MinX', mapping: 'extent > minx'},
{name: 'MinY', mapping: 'extent > miny'},
{name: 'MaxX', mapping: 'extent > maxx'},
{name: 'MaxY', mapping: 'extent > maxy'}
])
});

//Create the grid.
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: "Spatial Reference", width: 240, dataIndex: 'SR', sortable: false},
{header: "Min-X", width: 120, dataIndex: 'MinX', sortable: false},
{header: "Min-Y", width: 120, dataIndex: 'MinY', sortable: false},
{header: "Max-X", width: 120, dataIndex: 'MaxX', sortable: false},
{header: "Max-Y", width: 120, dataIndex: 'MaxY', sortable: false}
],
renderTo: 'example-grid',
width: 720,
height: 400
});

store.load();
});


What I'd like to do is dispay each attributes/attribute tag in a different column. How does the xpath work?

BitPoet
13 Jul 2010, 10:35 PM
As an XmlReader is supposed to consume more than one record, those records must be contained in the root node, not be the root node itself. So your result tags need to be wrapped inside a "document" tag, like

<data>
<result>
<attributes>...</attributes>
<extent>...</extent>
</result>
</data>
Then, positionally accessing one of a number of identically named attributes can be done via the :nth syntax as stated in the DomQuery docs.

{name: 'SR', mapping: 'attributes > attribute:nth(1)'}