How to Read an XML File in Java Script
XML (Extensible Markup Language) is the international standard for defining data descriptions to work on the Internet across varying operating systems and web browsers. Web services also use XML as the underlying data markup in order to permit communication and data exchange for both client and server side programming. Javascript can also be used to read XML files when programming web pages to conduct scripting based on user action and content saved in XML data files.
Instructions
-
-
1
Create a new, blank XML document contained in the head node of a web page by using the following code:
Var myXMLdoc = document.implementation.createDocument("","", null); -
2
Turn off asynchronous document loading to prevent the XML parser from attempting to continue with Javascript execution prior to the XML document being fully loaded by using the following code:
myXMLdoc.asynch="false"; -
-
3
Load the XML document into the Javascript parser with the following code:
myXMLdoc.load("myXMLFile.xml");
The XML file is now read and can be further manipulated as required for your web page.
-
1