PDA

View Full Version : What's wrong with my XMLReader?



hallikpapa
18 Aug 2007, 3:30 PM
Nothing is rendered in the grid and I don't see any errors in firefox. And there are no javascript errors.



<?xml version="1.0" encoding="utf-8"?>
<dataset>
<cdr>
<id>08-15-2007.09 </id>
<col2>202</col2>
<col3>7</col3>
<col4>7</col4>
<col5>0</col5>
<col6> 0.0</col6>
<col7>100</col7>
<col8> 1</col8>
<col9> </col9>
<col10>2007-08-15 09:57:56</col10>
</cdr><cdr>
<id>08-15-2007.09 </id>
<col2>202</col2>
<col3>8</col3>
<col4>8</col4>
<col5>0</col5>
<col6>1414.5</col6>
<col7>100</col7>
<col8> 1</col8>
<col9>10608</col9>
<col10>2007-08-15 09:57:56</col10>
</cdr><cdr>
<id>08-15-2007.11 </id>
<col2>240</col2>
<col3>12</col3>
<col4>12</col4>
<col5>0</col5>
<col6> 0.0</col6>
<col7>100</col7>
<col8> 2</col8>
<col9> </col9>
<col10>2007-08-15 11:57:15</col10>
</cdr></dataset>




var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '../../../cgi-bin/rpt.pl?name=NPAHR'}),
reader: new Ext.data.XmlReader({
record: 'cdr',
id: 'id'
},
[
'id', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9', 'col10'
]),
// turn on remote sorting
remoteSort: true
});
//we set the deafault sort to the id ascending
ds.setDefaultSort('id', 'asc');

// now we create the Grid Columns
var cm = new Ext.grid.ColumnModel([
{header: "Date.Hour", dataIndex: 'id', width: 125, sortable: true, align: 'left'},
{header: "", dataIndex: 'col2', width: 125, sortable: true},
{header: "Attempts", dataIndex: 'col3', width: 70, sortable: true},
{header: "Connects", dataIndex: 'col4', width: 70, sortable: true},
{header: "Errors", dataIndex: 'col5', width: 70, sortable: true},
{header: "Minutes", dataIndex: 'col6', width: 70, sortable: true},
{header: "ASR", dataIndex: 'col7', width: 70, sortable: true},
{header: "PDD", dataIndex: 'col8', width: 70, sortable: true},
{header: "ACD", dataIndex: 'col9', width: 70, sortable: true},
{header: "Last Call", dataIndex: 'col10', width: 150, sortable: true}
]);
// by default columns are sortable
cm.defaultSortable = true;

// create the grid
var grid = new Ext.grid.Grid('grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
loadMask: true,
enableColLock:true
});
// render the Grid
grid.render();

var gridFoot = grid.getView().getFooterPanel(true);
// add a paging toolbar to the grid's footer
var pagbar = new Ext.PagingToolbar(gridFoot, ds, {pageSize: 12});

ds.load({params:{start:0, limit:12}});

MaximGB
18 Aug 2007, 3:43 PM
Do you actually load anything?
Is there ds.load() call anywhere?

hallikpapa
18 Aug 2007, 3:51 PM
Sorry edited original post. This works great if I use JSON, but I have large datasets and it can't handle it, so I am trying out XML. So this has worked before, I just changed the way the data is outputted and to the XMLReader

MaximGB
18 Aug 2007, 3:54 PM
Still don't see ds.load().....

hallikpapa
18 Aug 2007, 4:00 PM
Still don't see ds.load().....

Yeah don't know how I missed that, but it's there.

MaximGB
18 Aug 2007, 4:11 PM
Shouldn't the record defention be like so:


var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '../../../cgi-bin/rpt.pl?name=NPAHR'}),
reader: new Ext.data.XmlReader({
record: 'cdr',
id: 'id'
},
[
{name: 'id'}, {name: 'col2'}, {name: 'col3'}......
]),
// turn on remote sorting
remoteSort: true

?

hallikpapa
18 Aug 2007, 4:29 PM
Upon further review, I printed the data to a file, and tried to view the file in the browser just as plain XML, and it couldn't read it. Apache said something about a malformed header.

It looks like most other examples of headers in this forum though....

MaximGB
18 Aug 2007, 4:30 PM
does you server sends content-type: text/xml header with response?

hallikpapa
21 Aug 2007, 7:33 AM
<edit> OK I got it working fine with XMLReader, it loads the data. But memory usage and processor jump to 150MB and 50% utilization. And both browsers say "should we stop this script?" But I keep saying no, and finally it displays data.

What's the largest dataset most people use in ext, or what's the largest that has been tested?

hallikpapa
21 Aug 2007, 8:57 AM
Here is a sample from a dataset only 100 rows long, and what it is returning properly now I have headers working fine:



<?xml version="1.0" encoding="ISO-8859-1"?>
<dataset>
<cdr>
<id>0 </id>
<col2>F</col2>
<col3>1</col3>
<col4>0</col4>
<col5>1</col5>
<col6></col6>
<col7></col7>
<col8></col8>
<col9></col9>
<col10>2007-08-20 20:08:27</col10>
</cdr>
.......
</dataset>



And here is the js that is supposed to be reading it, but the grid returns blank



// create the Data Store
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '../../../cgi-bin/rpt.pl?name=ISDNCODE'}),
reader: new Ext.data.XmlReader({
root: 'cdr',
id: 'id'
},
[
'id', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9', 'col10'
]),
// turn on remote sorting
remoteSort: true
});
//we set the deafault sort to the id ascending
ds.setDefaultSort('id', 'asc');

// example of custom renderer function
function italic(value){
return '<i>' + value + '</i>';
}

// example of custom renderer function
function dur(val){
if(val > 0){
return '<span style="color:green;">' + val + '</span>';
}else if(val = 0){
return '<span style="color:red;">' + val + '</span>';
}
return val;
}

// now we create the Grid Columns
var cm = new Ext.grid.ColumnModel([
{header: "ISDN Code", dataIndex: 'id', width: 150, sortable: true, align: 'left'},
{header: "Call Status", dataIndex: 'col2', width: 125, sortable: true},
{header: "Attempts", dataIndex: 'col3', width: 90, sortable: true},
{header: "Connects", dataIndex: 'col4', width: 90, sortable: true},
{header: "Errors", dataIndex: 'col5', width: 80, sortable: true},
{header: "Minutes", dataIndex: 'col6', width: 70, sortable: true},
{header: "ASR", dataIndex: 'col7', width: 70, sortable: true},
{header: "PDD", dataIndex: 'col8', width: 70, sortable: true},
{header: "ACD", dataIndex: 'col9', width: 70, sortable: true},
{header: "Last Call", dataIndex: 'col10', width: 70, sortable: true}
]);
// by default columns are sortable
cm.defaultSortable = true;

// create the grid
var grid = new Ext.grid.Grid('grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
loadMask: true,
enableColLock:true
});
// render the Grid
grid.render();

var gridFoot = grid.getView().getFooterPanel(true);
// add a paging toolbar to the grid's footer
var pagbar = new Ext.PagingToolbar(gridFoot, ds, {pageSize: 12});

ds.load({params:{start:0, limit:12}});

hendricd
21 Aug 2007, 9:00 AM
can your browser display your XML results properly from 'http://../../../cgi-bin/rpt.pl?name=ISDNCODE'?

Any parsing errors ?

hallikpapa
21 Aug 2007, 9:10 AM
Yes, here is a quick copy and paste of what the browser displays (only first two records shown)




This XML file does not appear to have any style information associated with it. The document tree is shown below.


<dataset>

<cdr>
<id>0 </id>
<col2>F</col2>
<col3>1</col3>
<col4>0</col4>
<col5>1</col5>
<col6/>
<col7/>
<col8/>
<col9/>
<col10>2007-08-20 20:08:27</col10>
</cdr>

<cdr>
<id>0 </id>
<col2>I</col2>
<col3>95060</col3>
<col4>95060</col4>
<col5>0</col5>
<col6> 0.0</col6>
<col7> </col7>
<col8> </col8>
<col9> </col9>
<col10>2007-08-20 23:59:58</col10>
</cdr>

So it's showing my data, but the js isn't grabbing it for some reason.

hendricd
21 Aug 2007, 9:16 AM
If that looks good,

Code:


Ext.Ajax.on( {'requestexception':function(){console.log(['requestexception',arguments])}
,'requestcomplete':function(){console.log(['requestcomplete',arguments])}
});

ds.load();

then see what's inside the response.responseXML(arguments[1]) property, that's your XMLDocument. Is there a firstChild node, (for IE its XML, Gecko is likely your root node or 'parsererror' if its not well-formed) , etc...

you should see the text version in the response.responseText property.

also look at the response.getAllResponseHeaders, Good Content-type header: [application]text/xml ?

hallikpapa
21 Aug 2007, 9:24 AM
OK I put that in there right before my ds.load, but I ran it through the gui and saw nothing...

Where should I be seeing the results you are looking for? Somewhere in firebug? Sorry, never seen that function before.

<edit> Sorry, my mistake. Here's what i see in firebug under console tab. Where would I find the data you are looking for? Somewhat new to firebug


["requestcomplete", [Object autoAbort=false events=Object transId=false, Object tId=0 status=200 statusText=OK, Object params=Object request=Object reader=Object]]

hendricd
21 Aug 2007, 9:29 AM
Look at the one that looks like:

[Object tId=0 status=200 statusText=OK]


also, you may want to remove those extraneous white-spaces, and tabs from your XML.

hallikpapa
21 Aug 2007, 9:38 AM
OK I think I am getting closer...I would think inside each element maybe a whitespace is ok, but inbetween elements, not so much. For instance, the perl does the new line (\n) but there seems to be a white space in between each element, IE:



<cdr>\n <id>0 </id>\n <col2>F</col2>\n <col3>1</col3>\n <col4>0</col4>\n <col5>


I have to find out how that is happening, but you think it's croaking on that?

hendricd
21 Aug 2007, 9:39 AM
what is that-objects.responseXML.firstChild.nodeName ?

hallikpapa
21 Aug 2007, 9:42 AM
"dataset"

also, tagname, localname, and nodename all say dataset.

hendricd
21 Aug 2007, 9:49 AM
You've got a working DOMDocument then.

You just need verify your reader and columnmodel definitions match your XML schema :


var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: '../../../cgi-bin/rpt.pl?name=NPAHR'}),
reader: new Ext.data.XmlReader({
record: 'cdr',
id: 'id'
},
[
'id', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9', 'col10'
]),
// turn on remote sorting
remoteSort: true
});
//we set the deafault sort to the id ascending
ds.setDefaultSort('id', 'asc');

// now we create the Grid Columns
var cm = new Ext.grid.ColumnModel([
{header: "Date.Hour", dataIndex: 'id', width: 125, sortable: true, align: 'left'},
{header: "", dataIndex: 'col2', width: 125, sortable: true},
{header: "Attempts", dataIndex: 'col3', width: 70, sortable: true},
{header: "Connects", dataIndex: 'col4', width: 70, sortable: true},
{header: "Errors", dataIndex: 'col5', width: 70, sortable: true},
{header: "Minutes", dataIndex: 'col6', width: 70, sortable: true},
{header: "ASR", dataIndex: 'col7', width: 70, sortable: true},
{header: "PDD", dataIndex: 'col8', width: 70, sortable: true},
{header: "ACD", dataIndex: 'col9', width: 70, sortable: true},
{header: "Last Call", dataIndex: 'col10', width: 150, sortable: true}

what does ds.on('loadexception', function(){....}) tell you ?

And, get your params out of the URL -- tacky. Use ds.load({params:{name:'NPAHR'}});

I gotta run, on Vacation now, you're on the right path. GO !

hallikpapa
21 Aug 2007, 10:05 AM
Have a good vacation. Thanks for getting me here.

I know this is a stupid question, but I see a "1 more" now that I have put this in



ds.on( {'loadexception':function(){console.log(['loadexception',arguments])},
'loadcomplete':function(){console.log(['loadcomplete',arguments])}
});





["loadexception", [Object events=Object conn=Object useAjax=true, Object params=Object request=Object reader=Object, Object tId=0 status=200 statusText=OK, 1 more...]]

The "loadexception" is red, although everythign I can see is green. Is that trying to tell me if I could click the "1 more" that's where my error might be?