:: Forum >>

How to pass an xml request to a grid

Hi,

I'm currently trying to figure out how to parse an xml result to the AW.grid.

I've got a search form enabling users to query a DB with (name, category,provenance,region variables) trigged by an onClick="query_texis();".

Once the values of the form are checked they are parsed to the server-side (vortex-texis) script that queries the database. All goes fine! Texis has a handy output option enabling the request to be output in xml.
<SQL output=xml "SELECT * FROM blablabal WHERE name like ...></SQL>

When I check the xmlHttp.responseTEXT i'm getting as planed an xml response. The trick I can't figure out is how to parse this variable (the xml string) to the AW.table and then to the grid functions.

Anyone have an idea?


The result of the server-side query; (var result = xmlHttp.responseTEXT;)

<? xml version="1.0" encoding="UTF-8" ?>
<results>
<result>
<NAME>Council of Europe </NAME>
<FURL>http://www.coe.int/defaulten.asp</FURL>
<CATEGORY>Prime Sources</CATEGORY>
<SUBCATEGORY>European Organizations</SUBCATEGORY>
<PROVENANCE></PROVENANCE>
<REGION></REGION>
</result>
<result>
<NAME>Asia Women's Human Rights Council</NAME>
<FURL>http://www.awhrc.org/index.htm</FURL>
<CATEGORY>Subject-Based Sources</CATEGORY>
<SUBCATEGORY>Women</SUBCATEGORY>
<PROVENANCE></PROVENANCE>
<REGION>Asia</REGION>
</result>
</results>

The scripts;
<script>
var xmlHttp = false; //check wich browser the user is using
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}

function query_texis(){
var name = document.getElementById('NAME').value;
var category = document.getElementById('CATEGORY').value;
var provenance = document.getElementById('PROVENANCE').value;
var region = document.getElementById('REGION').value;
var url = "xml1?name=" + escape(name) + "&category=" + escape (category) + "&provenance=" + escape(provenance) + "&region=" + escape(region);
// Open a connection to the server
xmlHttp.open("POST", url, true);
// Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage;
// Send the request
xmlHttp.send(null);
}

function updatePage(){
if(xmlHttp.readystate == 4){
var result = xmlHttp.responseTEXT;
alert(result);

var table = new AW.XML.Table; //can't figure out this bit
//table.setURL(result); //tried using getXML(result)
table.setAsync(false);
table.request();

var obj = new AW.UI.Grid;
obj.setId("grid");
obj.setHeaderText(["URL Name","URL","Category","Subcategory","Country","Region"]);
obj.setColumnCount(6);
obj.setCellData(table);
document.write(obj);
}
}
</script>

Alex_gwood
Monday, October 30, 2006
Check the examples that come with the Grid install.

Here is an example:

var itsTableZones = new AT.XML.Table;
itsTableZones.setURL(theURL);
itsTableZones.setRows('/result/zones/zone');
itsTableZones.setColumns(['zoneid','zonename','servername','viewname','zonetype']);
itsTableZones.setAsync(false);
itsTableZones.request();

// Now itsTableZones contains the XML
// Then you can simply loop through the itsTableZones using getData
// And set the Grid values using setCellText



Karl Thoroddsen
Tuesday, October 31, 2006
give a try to ths instead of using get data loop..

gridobj.setCellModel(table);
S.Onur SELAMET
Friday, November 3, 2006
Correct and much simpler, but only if the Table is identical to the Grid.
Karl Thoroddsen
Friday, November 3, 2006

This topic is archived.


Back to support forum

Forum search