I have an XML file with the following structure:
<FIELDS>
<GRP1>
<OPTION>
<VALUE>71</VALUE>
<CONTENT>Text</CONTENT>
</OPTION>
...
...
</GRP1>
<GRP2>
<OPTION>
<VALUE>77</VALUE>
<CONTENT>Test</CONTENT>
</OPTION>
</GRP2>
...
...
</FIELDS>
I need to get the node values of all child nodes of <OPTIONS> with <GRP1> as parent node.
I tried the following code but it did not work:
// [...]
var xmlGRP = xmlDoc.getElementsByTagName(GRP1);
xmlvalue = xmlGRP.childNodes[0].childNodes[0].firstChild.nodeValue;
xmlcontent = xmlGRP.childNodes[0].childNodes[1].firstChild.nodeValue;
Can anyone tell me what's wrong with my code?
getElementsByTagNamewould return a node list. you have to traverse it using for loop or if there is only one element by that name, try usingxmlGRP[0]