PDA

View Full Version : [SOLVED] XMLReader -> Node name = sub node name



maquejp
9 Jun 2008, 12:18 AM
Hi,

I am trying to generate a gridpanel with data from an XML generated by a specific tool that I can not modifiy (DVDProfiler for those who knows)

I succeed except that I have empty line in my grid, I think that it is due to the fact that a child node has the same name as the record node. Note the "DVD" has record node and the "DVD" a "MediaTypes" child node.

Anybody got that problem already and fix it?
Thanks


<Collection>
<DVD>
<ProfileTimestamp>2007-09-03T20:59:38.000Z</ProfileTimestamp>
<ID>0044007807828.9</ID>
<MediaTypes>
<DVD>True</DVD>
<HDDVD>False</HDDVD>
<BluRay>False</BluRay>
</MediaTypes>
<UPC>0-044007-807828</UPC>
<CollectionNumber>142</CollectionNumber>
<CollectionType>Owned</CollectionType>
<Title>Spawn</Title>
...
</DVD>
<DVD>reading it with


Ext.onReady(function() {
var dataStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'Collection.xml',
method:'GET'}),
reader: new Ext.data.XmlReader({
record: 'DVD',
id: 'ID'
}, [
{name:'CollectionNumber', type:'float'}, 'Title'
])
});

var colModel = new Ext.grid.ColumnModel([
{header: "#", width: 1, dataIndex: 'CollectionNumber', sortable: true},
{header: "Title", width: 590, dataIndex: 'Title', sortable: true}
]);

var filters = new Ext.grid.GridFilters({
filters:[
{type: 'numeric', dataIndex: 'CollectionNumber'},
{type: 'string', dataIndex: 'Title'}

]});

var grid = new Ext.grid.GridPanel({
ds: dataStore,
cm: colModel,
title: 'List of DVD',
stripeRows: true,
enableColLock: false,
loadMask: true,
viewConfig: {
forceFit:true
},
renderTo:'DVDcontent',
plugins: filters,
height:600

});
grid.render();
dataStore.load();

});

illuminum
9 Jun 2008, 5:31 AM
Does
record: 'Collection/DVD' work for you?

maquejp
9 Jun 2008, 5:44 AM
Nope, no data displayed...

illuminum
9 Jun 2008, 6:04 AM
Hmm that sucks. I would check the xmlreader source code and see how it works under the hood. Last time I had a problem I just prodded and took shots in the dark until it worked but in retrospect I should've just studied the underlying source. I don't think it uses real xpath, otherwise you could get at the record a number of ways. I could be wrong...

maquejp
9 Jun 2008, 6:20 AM
that's sad ... I do not want to write a script to process the generated XML to produce another XML that would comply for... With unique node name...

I hope that the support can find solution/workaround

Thank by the way

maquejp
10 Jun 2008, 11:03 PM
Nobody can help me?

Animal
10 Jun 2008, 11:40 PM
What is the problem?

Is the Store being loaded with anything at all?

Is the XmlReader firing a "loadexception" event?

maquejp
10 Jun 2008, 11:58 PM
http://maquestiaux.net/dvd/

Store loaded, No exception raised

It "works" but I have "extra" lines in the GRID. (see the empty odd lines when not sorting the result)

The record is the node <dvd>...</dvd> withing the root <collection>...</collection>
BUT there is a node also called <dvd> within the child node <MediaTypes> of <dvd>

xmlpath Collection/DVD
xmlpath Collection/DVD/MediaTypes/DVD

Animal
11 Jun 2008, 1:40 AM
I can't get the page to work. I blocked that "urchin" thing that people put in their pages a lot, so it knacked it.

maquejp
11 Jun 2008, 1:51 AM
I can't get the page to work. I blocked that "urchin" thing that people put in their pages a lot, so it knacked it. Well it is for GOOGLE Stats... I comment the lines...
And attache a screen cap...

Animal
11 Jun 2008, 5:08 AM
record: 'Collection/DVD'


Should work.

Step into XmlReader and see what's happening.

maquejp
11 Jun 2008, 6:08 AM
record: 'Collection/DVD'


Should work.

Step into XmlReader and see what's happening.

If I use this annotation I have no result displayed in the grid.

What do you mean by "step into" ? the -debug.js ? I tried but no difference (and I do not see any debug like stuff)

Animal
11 Jun 2008, 6:23 AM
You'll have to use a breakpoint because the results are processed in an event handler, but yes, stepping throuigh ext-all-debug.js

maquejp
12 Jun 2008, 3:18 AM
Sorry but:how do I add break point?

I am trying to apply an XSLT but it looks like that it is not taken into account by the XmlReader...

Animal
12 Jun 2008, 3:20 AM
find the correct line in ext-all-debug.js, click in the margin, and a BP is set.

maquejp
12 Jun 2008, 3:33 AM
What tool do yo use? I code with PSPad and Dreamweaver...

Animal
12 Jun 2008, 3:45 AM
Firebug. How else can you debug?

maquejp
12 Jun 2008, 3:53 AM
Firebug. How else can you debug?
So with FF ok ...

illuminum
12 Jun 2008, 5:50 AM
Collection/DVD probably doesn't work because 'Collection' is the root node

Here's a shot in the dark: '/DVD'

If you post an entire snippet of code that can run on its own then I'll copypaste it and try it out for you. I remember quite well how frustrating a similar predicament was for me when I had no control over the server-side XML

maquejp
12 Jun 2008, 6:39 AM
Finally I have created a PHP script that parse the XML with an XSLT and return the XML nodes needed for my Grid...

Thanks...
But it was this

Ext.onReady(function() {

var dataStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: 'Collection.xml',
method:'GET'}),
reader: new Ext.data.XmlReader({
record: 'DVD',
id: 'ID'
}, [
{name:'CollectionNumber', type:'float'}, 'Title','Loaned'
])
});
var colModel = new Ext.grid.ColumnModel([
{header: "#", width: 20, dataIndex: 'CollectionNumber', sortable: true},
{header: "Title", width: 590, dataIndex: 'Title', sortable: true}
]);
dataStore.load();
gridView = new Ext.grid.GridView({
forceFit: true,
getRowClass : function (row, index) {
var cls = '';
var data = row.data;
switch (data.Loaned) {
case 'False' :
cls = ''
break;
case 'True' :
cls = 'green-row'
break;
}
return cls;
}
});
var grid = new Ext.grid.GridPanel({
ds: dataStore,
cm: colModel,
title: 'List of DVD',
stripeRows: true,
view: gridView,
enableColLock: false,
loadMask: true,
viewConfig: {
forceFit:true
},
renderTo:'DVDcontent',
height:600
});
grid.render();

});

Animal
12 Jun 2008, 7:18 AM
Collection/DVD probably doesn't work because 'Collection' is the root node

Here's a shot in the dark: '/DVD'



That must be it. Of course, there's no "Collection" node in each row! DOH! So yes, either "/DVD" or "./DVD" has to work!

maquejp
12 Jun 2008, 10:40 AM
I will give it a try tommorow

By the way, thanks guys for the help