:: Forum >>
get xml nodes PLEASE HELP! :)
How do I make an array that contains the text inside a specific tag name of an XML file.
I know i must use table.getXML() and something like selectNode() but I can't seem to get an answer from the forums.
Please Help me.
thanks
Thursday, March 23, 2006
Here is the modified table.response method which builds an array of text from the first column and assigns it to the grid row selector -
table.response = function(xml){
this.setXML(xml);
var array = [];
var max = this.getCount();
var row, col = 0;
for (row = 0; row < max; row++){
array[row] = this.getData(col, row);
}
if (this.$owner) {
this.$owner.clearScrollModel();
this.$owner.clearSelectionModel();
this.$owner.clearSortModel();
this.$owner.clearRowModel();
this.$owner.setRowCount(this.getCount());
this.$owner.setSelectorText(array);
this.$owner.refresh();
}
}
I think if you need a solution which works in both IE and FF then its easier defining additional table column with XPath and use table.getData(col, row) method.
Alex (ActiveWidgets)
Thursday, March 23, 2006
Alex (ActiveWidgets)
Thursday, March 23, 2006
WOW, The XPath is very clear to me now thank you.
But this example still didn't work for me, i'm using FF (until i get a decsent demo made)?
So you are saying, make another table column with XPath (for instance @name) using:
table.setColumns(["@name", ...'grid data columns'....]);
Then make the selectors by:
array[row]=table.getData(col,row);
table.setSelectorText(array);
But won't this now display the new '@name' column in my grid as the first column??
Ben
Thursday, March 23, 2006
Oh wait,
i can do it like this:
table.setColumns([...'grid data columns'....,"@name"]);
grid.setColumnCount('one less than #of table columns');
and the last column wont be displayed correct?
Ben
Thursday, March 23, 2006
yes, exactly!
Alex (ActiveWidgets)
Thursday, March 23, 2006
PERFECT.
what about say if i needed and update time....so the xml was
<xml>
<updtime>"March 23, 2006"</updtime>
<row>
<col></col>
<col></col>
....
</row>
<row>...</row>
<row>...</row>
</xml>
Can I pick out the updtime as a variable just to write it to a <div> tag? Without having updtime as a row. (even if it was an attribute of <xml>!)
Ben
Thursday, March 23, 2006
You can do something like -
var node = table.getXML().documentElement.childNodes[1];
var text = AW.ie ? node.text : node.textContent;
alert(text);
It might be childNodes[1] or childNodes[0] depending whether you have anything between <xml> and <updtime>. Also IE and FF treat whitespace differently, so I would still define a column with XPath to avoid all this (XPath = "/updtime" or maybe "//updtime" to be sure :-)
Alex (ActiveWidgets)
Thursday, March 23, 2006
Thanks very much.
Ben
Friday, March 24, 2006
This topic is archived.
Back to support forum
Forum search