May 27, 2021 XML DOM
Most browsers have built-in XML parsers for reading and operating XML.
The parser converts XML to JavaScript accessable objects (XML DOMs).
XML DOM contains methods (functions) for traversing the XML tree to access, insert, and delete nodes.
However, it must be loaded into the XML DOM object before the XML document can be accessed and operated.
The XML parser reads the XML and converts it to an XML DOM object so that it can be accessed using JavaScript.
Most browsers have a built-in XML parser.
The following JavaScript fragment loads an XML document ("books.xml"):
Code interpretation:
The following code loads and parses an XML string:
Note: Internet Explorer uses the loadXML() method to parse XML strings, while other browsers use DOMParser objects.
For security reasons, modern browsers do not allow cross-domain access.
This means that the web page, as well as the XML file, must be on the same server as the attempt to load.
All open XML files in the instance on W3CSchool are on the W3CSchool domain.
If you want to use the instance above on your web page, the XML file you loaded must be on your own server.