XML DOM parser
Most browsers have built-in XML parsers for reading and manipulating XML.
The parser converts XML into a JavaScript-accessible object (XML DOM).
XML parser
The XML DOM contains methods (functions) for traversing XML trees, and accessing, inserting, and deleting nodes.
However, before an XML document can be accessed and manipulated, it must be loaded into an XML DOM object.
The XML parser reads XML and converts it into an XML DOM object, so that it can be accessed using JavaScript.
Most browsers have a built-in XML parser.
Load an XML document
The following JavaScript snippet loads an XML document ("books.xml"):
Example
Try it Yourself »
Code explanation:
- Create an XMLHTTP object
- Open an XMLHTTP object
- Send an XML HTTP request to the server
- Set the response as an XML DOM object
Load an XML string
The following code loads and parses an XML string:
Example
Try it Yourself »
Note:Internet Explorer uses the loadXML() method to parse XML strings, while other browsers use the DOMParser object.
Cross-origin Access
For security reasons, modern browsers do not allow cross-domain access.
This means that the web page and the XML file must be located on the same server when attempting to load.
In the examples on the Example tutorial site, all opened XML files are located on the Example domain.
If you want to use the above examples on your own web page, the XML file you load must be located on your own server.
other extensions