0

I have an XML string in which Val.responseText gives me

<NewDataSet>
  <Table>
    <FieldID>21</FieldID>
    <TableName>F003v001</TableName>
    <FieldName>Grade</FieldName>
    <DisplayField>Grade</DisplayField>
    <FieldType>text</FieldType>
  </Table>
</NewDataSet>

I'm 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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You muight find this helpful also:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.