Consider a XML document books.xml. The below code will parse this XML document into an XML document object or DOM.

   xmlhttp=new XMLHttpRequest();

 xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

Now, Consider the case when you have an XML String on a client side and you want to convert it into a DOM object. This also can be achieved using javascript by using the below code snippet.

txt="<Customer>";
txt=txt+"<title>JavaGenious</title>";
txt=txt+"<author>www.javagenious.com</author>";
txt=txt+"<year>2007</year>";
txt=txt+"</Customer>";

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

 




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)