DOM – Document Object Model is a language independent interface where each Node is an Object provides the data of the document in the XML tree structure. The standard is maintained by W3C (World Wide Web Consortium) XML DOM provides the details to get, change, add & delete XML elements in a XML document.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!DOCTYPE html> <html> <head> </head> <body> Name:<span id="nodevaluename"></span><br/> Roll Number :<span id="nodevaluerollnumber"></span><br/> <script> function testXMLDoc() { var xmlString = "<?xml version=\"1.0\" standalone=\"yes\"?>" + "<Students>" + " <Department branch=\"Computer\"> " + " <Name> John </Name> " + " <RollNumber> 6260 </RollNumber> " + " </Department> " + "</Students>"; var domParser = new DOMParser(); var xmlDoc = domParser.parseFromString(xmlString, "text/xml"); document.getElementById("nodevaluename").innerHTML = (xmlDoc.getElementsByTagName("Name")[0].childNodes[0].nodeValue); document.getElementById("nodevaluerollnumber").innerHTML = new XMLSerializer().serializeToString(xmlDoc.getElementsByTagName("RollNumber")[0]); } testXMLDoc(); </script> </body> </html> |