3.2.0

Get Column Headers from XML

There were several topics like this but I was unable to understand or implement the answers provided. I am using xmlHttp .responseText (not responseXML) to retrieve a string that contains xml data that looks like this:

<?xml version="1.0" ?>
<companies>
<company>
<ticker>MSFT</ticker>
<name>Microsoft Corporation</name>
<mktcap>314,571.156</mktcap>
<sales>32,187.000</sales>
<employees>55000</employees>
</company>
<company>
<ticker>ORCL</ticker>
<name>Oracle Corporation</name>
<mktcap>62,615.266</mktcap>
<sales>9,519.000</sales>
<employees>40650</employees>
</company>

How would I set the column headers from the XML?
How would I set the row count from the XML?
Eric Juvet
May 8,
How do you parse this string? With a separate XML parser object?
Alex (ActiveWidgets)
May 9,
Alex:

I figured it out. I use xmlHttp to get an XML string from our server. The XML string is a recordset that has been converted to XML. This is XML string is exactly the same is if it were on disk as an XML file.

The function loadXMLString will take the XML string and put it into a xmlDocument object. The loop at the end of this message show how I got the field name out of the xml. The field names are now in an array called Columns. Then setHeaderText(columns) just as shown in the many AW examples.

function loadXMLString(txt) {
try //Internet Explorer
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(txt);
return(xmlDoc);
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
parser=new DOMParser();
var xmlDoc=parser.parseFromString(txt,"text/xml");
return(xmlDoc);
}
catch(e) {alert(e.message)}
}
return(null);
}

// x is an XML dom object
var x = loadXMLString(fXmlString).documentElement;
y = x.childNodes;
z = y[0].childNodes;

// define column labels
var columns = [];
for (i=0;i<15;i++) {
columns[i] = z[i].getAttribute("name");
}

Eric Juvet
May 9,

This topic is archived.

See also:


Back to support forum