PDA

View Full Version : Grid import XML data help



Bobafart
5 Feb 2007, 12:38 PM
this is killing me.. I have been trying to figure out how to import my XML into my grid.. followed the blog posts and the docs and no luck.

I am unsure why the data refuses to load in. The columns are set up and the grids are in place but the data doesn't show up in any of the cells.



var XmlExample = {
init : function(){
var schema = {
tagName: 'item',
fields: ['Number', 'Weapon', 'Price', 'Country of Origin']
};
dataModel = new YAHOO.ext.grid.XMLDataModel(schema);

// the DefaultColumnModel expects this blob to define columns. It can be extended to provide
// custom or reusable ColumnModels
var colModel = new YAHOO.ext.grid.DefaultColumnModel([
{header: "id", width: 30, sortable: true},
{header: "weaponName", width: 140, sortable: true},
{header: "weaponPrice", width: 115, sortable: true},
{header: "weaponCountryOrigin", width: 140, sortable: true}
]);

// create the Grid
var grid = new YAHOO.ext.grid.Grid('example-grid', dataModel, colModel);
grid.autoWidth = true;
grid.autoHeight = true;
grid.render();

dataModel.load('php/shop.php');
}
}
YAHOO.ext.EventManager.onDocumentReady(XmlExample.init, XmlExample, true);



and my XML file format is all good:



<rss version="2.0">

<channel>

<item>
<id>1</id>
<weaponName>AK-47</weaponName>
<weaponPrice>500</weaponPrice>
<weaponCountryOrigin>Russian</weaponCountryOrigin>
</item>

<item>
<id>2</id>
<weaponName>Uzi Pistol</weaponName>
<weaponPrice>0</weaponPrice>
<weaponCountryOrigin>Israel</weaponCountryOrigin>
</item>

<item>
<id>3</id>
<weaponName>Beretta</weaponName>
<weaponPrice>0</weaponPrice>
<weaponCountryOrigin>Italian</weaponCountryOrigin>
</item>

<item>
<id>4</id>
<weaponName>Heckler & Koch MP5</weaponName>
<weaponPrice>0</weaponPrice>
<weaponCountryOrigin>Germany</weaponCountryOrigin>
</item>

<item>
<id>5</id>
<weaponName>Hydrogen Bomb</weaponName>
<weaponPrice>0</weaponPrice>
<weaponCountryOrigin>USA</weaponCountryOrigin>
</item>

<item>
<id>6</id>
<weaponName>Anthrax</weaponName>
<weaponPrice>0</weaponPrice>
<weaponCountryOrigin>Germany</weaponCountryOrigin>
</item>
</channel>
</rss>


has anyone else had success with this? what am I doing incorrectly? thanks in advance

tryanDLS
5 Feb 2007, 12:53 PM
The names you specify in your schema have to match the element names in the XML. You reversed the schema and the header column names in your code.

Bobafart
5 Feb 2007, 1:04 PM
yup.. now I feel like a moron.

ok.. when you start making dumb mistakes like that it is time to sleep.

g'nite