3.2.0

Loading XML for dummies...

Hi - intrigued by this datagrid thing, looks like it could be very useful to us as a reporting tool. Nice work. Anyway - onto my question:

I'm trying to load XML that's structured roughly thus:
<dataroot>
<ProductData>
<ProductSet pName="Dave">
<sku_id>1543</sku_id>
<product_id>CVLC13</product_id>
<description>Ibble</description>
<country>Obble</country>
<region>Bob</region>
</ProductSet>
<ProductCopy>
..some stuff..
</ProductCopy>
<ProductPictures>
..some stuff..
</ProductPictures>
</ProductData>
</dataRoot>

I would like the grid to create a row for each ProductData node, and columns based on the 5 nodes under each ProductSet node.

My code, thus far, looks like this: (don't laugh..)
<html>
<head>
<link href="runtime/classic/activeui.css" rel="stylesheet" type="text/css" />
<script src="runtime/activeui.js"></script>
</head>
<body>
<script>
var xPaths=new Array("/dataroot/productData/productSet/sku_id","/dataroot/productData/productSet/product_id","/dataroot/productData/productSet/description","/dataroot/productData/productSet/country","/dataroot/productData/productSet/region")

var table = new Active.XML.Table;
table.setURL("data/kevinTheXMLfile.xml");
table.setColumns(xPaths);
table.request();

var obj = new Active.Controls.Grid;
obj.setProperty("column/count", 5);
obj.setModel("data", table);

document.write(obj);
</script>
</body>
</html>

And, unsurprisingly, I'm not getting the results I'm expecting. What I AM getting, is a page that loads without any apparent errors containg a datagrid with four columns named "Column 1", "Column 2" etc, and about 130-140 rows. Rows 1-99 are numbered, after that the rows have no label. Every cell contains the value "null".

Any and all help much appreciated.
Wintermute
February 26,
You are nearly there. Just need to specify column XPath relative to the row node (i.e. ProductData):

var xPaths = ["productSet/sku_id", "productSet/product_id", "productSet/description", "productSet/country", "productSet/region"];

The row header numbers >99 are not visible because the header width is too small.

obj.setRowHeaderWidth(40);

also you may look at the example files like:

/examples/grid/xml-dataset.htm
Alex (ActiveWidgets)
February 26,
Hi Alex, thanks very much for your help - I am very nearly there :) but I still can't get anything other than "null" in my grid cells :(

This is my latest attempt at the correct script:
<script>
var string = new Active.Formats.String;

var table = new Active.XML.Table;
table.setURL("data/test.xml");
table.setRows("//dataroot/ProductData/*");
table.setColumns(["productSet/sku_id", "productSet/product_id", "productSet/description", "productSet/country", "productSet/region"]);
table.setFormats([string, string, string, string, string]);
table.request();

var columns = ["SKU ID", "Product ID", "Description", "Country", "Region"];

var obj = new Active.Controls.Grid;
obj.setProperty("column/texts", columns);
obj.setRowHeaderWidth(40);
obj.setModel("data", table);

document.write(obj);
</script>

and this - having just seen your example xml-dataset file and all the schema info in there - is what the opening lines of my test.xml file looks like:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<dataroot>
<EditionData>
<EditionName>Edition12</EditionName>
<DateStamp>12/02/2004 15:27:00</DateStamp>
</EditionData>
<ProductData pType="Accommodation">
<ProductSet>
<sku_id>1543</sku_id>
<product_id>CVLC13</product_id>
<description>A Campana</description>

could the problem be with my data rather than my script?

Thanks very much for your time, I promise once I've had it patiently drilled into me several times I'll stop pestering you. :)
Wintermute
February 27,
Looks like you use 'productSet' instead of 'ProductSet'. This might be a problem as XML/XPath is case-sensitive.
Alex (ActiveWidgets)
February 27,
Replace:
table.setRows("//dataroot/ProductData/*");
with:
table.setRows("//dataroot/ProductData");

... and it works for me.


M.
Martin
February 23,

This topic is archived.

See also:


Back to support forum