3.2.0

XML attributes

Hi.
I want to take an XML attribute (or tag name) and use it as the row selector text.

Forexample, my xml now looks like this:
<gridpoint>
<time1>some text</time1>
<time2>some text</time2>
...
<time71>some text</time71>
</gridpoint>

I would like to have something like the following:
<gridpoint name="St. John's">
....
</gridpoint>
OR
<gridpoint>
<name>St. John's</name>
<time1>some text</time1>
....
</gridpoint>

I would use "name" as the text that goes in the row selector.

As of right now I'm including a .js file with an array of names, it would be much easier to just include that information with the xml file.
Any easy way of doing this?
Thanks in advance.
Ben
March 21,
bump
Ben
March 21,
After the XML data is loaded into AW.XML.Table object you can get access to it with getXML() method and build selector names array iterating through the attributes list.

The XML is loaded asynchronously - you have to put your code into .response(xml) method (callback).
Alex (ActiveWidgets)
March 21,
Ok, so here is what I've got, is this right so far??

var defaultResponse = table.response;  
table.response = function(xml){ 
  	defaultResponse.call(this, xml); 

            //SOMETHING HERE TO GET NAMES???

  	//*set grid height
    hgt=table.getCount()*60;
    hgt += 45;
    if(hgt>530)
        hgt=530;
    obj.setStyle("height", hgt + "px");
}


in that function i need this:

var xmlDoc=getXML();

but how do i actually irate the name tag from xmlDoc, i can't seem to get it to work?

the xml document looks more like this:
<arrayOfGridPoints>
<gridPoint>
<name>...</name>
<time1>...</time1>
....
</gridPoint>
<gridPoint>
<name>...</name>
<time1>...</time1>
...
</gridPoint>
....
</arrayOfGridPoints>

I dispay the <time> data ignoring name, but now how can I get the values in <name> to store in an array.
Ben
March 22,
Ok, u can get help in http://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript

But ill help u, do something like this:

table.response = function(xml){  
   var resolver = createNSResolver( xml.ownerDocument == null ?    xml.documentElement :   xml.ownerDocument.documentElement);
  // iterate
  var iterator = xml.evaluate('//arrayOfGridPoints//gridPoint', xml, resolver, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
  var next = null;
   while((next=iterator.iterateNext()) != null) {
         // get the value of tag name
         alert(next.childNodes.item(0).textContent);
        // get the value of tag time1
        alert(next.childNodes.item(1).textContent);
         ....

   }		
}

Hope this help, cya.
Paulo Cesar Silva Reis (PC from Brazil).
July 12,

This topic is archived.

See also:


Back to support forum