Home »
MCQs »
XML MCQs
Which is the correct XML DOM statement to get the text value of the first element named 'city' in an XML document?
38. Which is the correct XML DOM statement to get the text value of the first element named "city" in an XML document?
- result = xmlDoc.getElementsByTagName("city")([0]).childNodes[0].nodeValue;
- result = xmlDoc.getElementsByTagName("city").childNodes[0].nodeValue;
- result = xmlDoc.getElementsByTagName("city")[0].nodeValue;
- result = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
Answer: D) result = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;
Explanation:
The correct XML DOM statement to get the text value of the first element named "city" in an XML document is:
result = xmlDoc.getElementsByTagName("city")[0].childNodes[0].nodeValue;