XML Parser

XML Parser

Many times, there is a requirement to parse XML response. By parsing, we mean taking out the required information from a bunch of coded data. In this situation, we will already have the XML response in a variable. In the syntax and examples given below, we will parse required data from an XML code.


If you already have your XML data in a variable e.g. input.

Then, to parse we will write given code:

parser = new DOMParser();

xmlDoc = parser.parseFromString(input,”text/xml”);


XML parser

In the example mentioned above, we have the XML code in our variable “input”. That is then parsed (or accessed) into another variable “xmlDoc”. Later, we have picked the title of the book from XML. This code was written in console of browser (press F12 to open console). These codes are written in JavaScript which will be discussed later.
The output is highlighted above.


Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.