tags:

views:

253

answers:

2

I have an xml string

sVal.responseText gives me

< NewDataSet >

  < Table >

    <FieldID>21</FieldID>

    <TableName>F003v001</TableName>

    <FieldName>Grade</FieldName>

    <DisplayField>Grade</DisplayField>

    <FieldType>text</FieldType>

  < /Table >

</NewDataSet>

i am calling FillTable(sVal.responseXML.documentElement);

function FillTable(sResponse) {

    var preXML = sResponse;

    // code for IE
    if (window.ActiveXObject) {
        var doc = new ActiveXObject("Microsoft.XMLDOM");
        doc.async = "false";
        doc.loadXML(preXML);
    }
    // code for Mozilla, Firefox, Opera, etc.
    else {
        var parser = new DOMParser();
        var doc = parser.parseFromString(preXML, "text/xml");
    }

    // documentElement always represents the root node
    var x = doc.documentElement;

}

Now i want to parse through each of the node and populate a datagrid. Can anyone help me parse through the nodes?

How do i get the values for fieldid,tablename,displayfield?

I tried NodeList = doc.documentElement.selectNodes("Table")

but nodelist.length gives me zero.

Please help Thanks

+1  A: 

http://www.w3schools.com/Dom/dom_methods.asp

use the doc variable you created, instead of the documentElement, then you can use these methods on it.

Luca Matteis
+1  A: 

You muight find this helpful also:

http://www.hiteshagrawal.com/javascript/javascript-parsing-xml-in-javascript

epascarello