3.0 beta 2

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
March 23,
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; // take data from col 0

        // build array of values from 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)
March 23,
Just want to add that you can use any complex XPath to specify where your column data is, for example

@attributeName - get value of an attribute
elementName[@attrName='someValue']/@anotherAttr - get anotherAttr from the child node of an elementName where attrName = someValue :-)

See examples -

/datagrid.8255/data-island-help-alex.html
/datagrid.9193/xpath-xml.html
Alex (ActiveWidgets)
March 23,
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:
//for all rows
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
March 23,
Oh wait,
i can do it like this:

table.setColumns([...'grid data columns'....,"@name"]);  
//...do selector stuff here...
grid.setColumnCount('one less than #of table columns');


and the last column wont be displayed correct?
Ben
March 23,
yes, exactly!
Alex (ActiveWidgets)
March 23,
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
March 23,
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)
March 23,
Thanks very much.
Ben
March 24,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.