The Document Object Model (DOM) is the foundation of XML. XML documents have a hierarchy of informational units called nodes; DOM is a way of describing those nodes and the relationships between them.
XML - DOM Home Whiteboard Practice Code Graphing Calculator Online Compilers Articles Tools Categories Explore Categories Find the perfect tutorial for your learning journey Python TechnologiesDatabasesComputer ProgrammingWeb DevelopmentJava TechnologiesComputer ScienceMobile DevelopmentBig Data & AnalyticsMicrosoft TechnologiesDevOpsLatest TechnologiesMachine LearningDigital MarketingSoftware QualityManagement Tutorials View All Categories Tutorials Courses Jobs Login XML - Home XML - Overview XML - Syntax XML - Documents XML - Declaration XML - Tags XML - Elements XML - Attributes XML - Comments XML - Character Entities XML - CDATA Sections XML - White Spaces XML - Processing XML - Encoding XML - Validation XML - DTDs XML - Schemas XML - Tree Structure XML - DOM XML - Namespaces XML - Databases XML Tools XML - Viewers XML - Editors XML - Parsers XML - Processors XML Useful Resources XML - Quick Guide XML - Useful Resources Selected Reading UPSC IAS Exams Notes Developer's Best Practices Questions and Answers Online Resume Builder HR Interview Questions Computer Glossary Who is Who Home Xml XML - DOM XML - DOM Previous Quiz Next The Document Object Model (DOM) is the foundation of XML. XML documents have a hierarchy of informational units called nodes; DOM is a way of describing those nodes and the relationships between them. A DOM document is a collection of nodes or pieces of information organized in a hierarchy. This hierarchy allows a developer to navigate through the tree looking for specific information. Because it is based on a hierarchy of information, the DOM is said to be tree based. The XML DOM, on the other hand, also provides an API that allows a developer to add, edit, move, or remove nodes in the tree at any point in order to create an application. Example The following example (sample.htm) parses an XML document ("address.xml") into an XML DOM object and then extracts some information from it with JavaScript − <!DOCTYPE html> <html> <body> <h1>TutorialsPoint DOM example </h1> <div> <b>Name:</b> <span id = "name"></span><br> <b>Company:</b> <span id = "company"></span><br> <b>Phone:</b> <span id = "phone"></span> </div> <script> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","/xml/address.xml",false); xmlhttp.send(); xmlDoc = xmlhttp.responseXML; document.getElementById("name").innerHTML= xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue; document.getElementById("company").innerHTML= xmlDoc.getElementsByTagName("company")[0].childNodes[0].nodeValue; document.getElementById("phone").innerHTML= xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue; </script> </body> </html> Contents of address.xml are as follows − <?xml version = "1.0"?> <contact-info> <name>Tanmay Patil</name> <company>TutorialsPoint</company> <phone>(011) 123-4567</phone> </contact-info> Now let us keep these two files sample.htm and address.xml in the same directory /xml and execute the sample.htm file by opening it in any browser. This should produce the following output. Here, you can see how each of the child nodes is extracted to display their values. Print Page Previous Quiz Next Advertisements ABOUT US OUR TEAM CAREERS JOBS CONTACT US TERMS OF USE PRIVACY POLICY REFUND POLICY COOKIES POLICY FAQ'S Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical and non-technical subjects. Copyright 2026. All Rights Reserved.