XML Parser

Most browsers have a built-in XML parser to read and manipulate XML. The parser converts XML into a JavaScript accessible object. Parsing X...


Most browsers have a built-in XML parser to read and manipulate XML.
The parser converts XML into a JavaScript accessible object.

Parsing XML

All modern browsers have a built-in XML parser that can be used to read and manipulate XML.
The parser reads XML into memory and converts it into an XML DOM object that can be accessed with JavaScript.
You will learn more about the XML DOM in the next chapter of this tutorial.
There are some differences between Microsoft's XML parser and the parsers used in other browsers. The Microsoft parser supports loading of both XML files and XML strings (text), while other browsers use separate parsers. However, all parsers contain functions to traverse XML trees, access, insert, and delete nodes (elements) and their attributes.
In this tutorial we will show you how to create scripts that will work in both Internet Explorer and other browsers.
Note: When we talk about parsing XML, we often use the term "Nodes" about XML elements.

Loading XML with Microsoft's XML Parser

Microsoft's XML parser is built into Internet Explorer 5 and higher.
The following JavaScript fragment loads an XML document ("note.xml") into the parser:

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("note.xml");

Example explained:
  • The first line of the script above creates an empty Microsoft XML document object.
  • The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.
  • The third line tells the parser to load an XML document called "note.xml".
The following JavaScript fragment loads a string called txt into the parser:

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(txt);

Note: The loadXML() method is used for loading strings (text), load() is used for loading files.

XML Parser in Firefox and Other Browsers

The following JavaScript fragment loads an XML document ("note.xml") into the parser:

var xmlDoc=document.implementation.createDocument
("","",null);
xmlDoc.async="false";
xmlDoc.load("note.xml");

Example explained:
  • The first line of the script above creates an empty XML document object.
  • The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.
  • The third line tells the parser to load an XML document called "note.xml".
The following JavaScript fragment loads a string called txt into the parser:

var parser=new DOMParser();
var doc=parser.parseFromString(txt,"text/xml");

Example explained:
  • The first line of the script above creates an empty XML document object.
  • The second line tells the parser to load a string called txt.
Note: Internet Explorer uses the loadXML() method to parse an XML string, while other browsers uses the DOMParser object.
Name

ADO,131,ASP,3,C++,61,CORE JAVA,1,CSS,115,HTML,297,index,5,JAVASCRIPT,210,OS,47,PHP,65,SAD,53,SERVLETS,23,SOFTWARE ENGINEERING,245,SQL,71,TCP/IP,1,XHTML,9,XML,18,
ltr
item
Best Online Tutorials | Source codes | Programming Languages: XML Parser
XML Parser
Best Online Tutorials | Source codes | Programming Languages
https://www.1000sourcecodes.com/2012/05/xml-parser.html
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/
https://www.1000sourcecodes.com/2012/05/xml-parser.html
true
357226456970214079
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content