Re: creating the parseObject in Mozilla

Martin Honnen <[email protected]> Sun, 16 Dec 2007 13:43:36 +0100
Newsgroups gmane.comp.mozilla.devel.xml
Organization Liberty Development
Message-ID <[email protected]>
[email protected] wrote:
> How do I create an instance of the XML parser in Mozilla or load an
> xml document into the mozilla browser?

If you want to parse from a string use
   var xmlDoc = new DOMParser().parseFromString(yourXmlString, 
'application/xml');

If you want to parse from a file or URL then you have two options:
1) create an XML DOM document and call its load method:
    var xmlDoc = document.implementation.createDocument('', 'root', null);
    xmlDoc.onload = function () {
      // access DOM here
    };
    xmlDoc.load('file.xml');
Note that loading by default happens asynchronously so you need to set 
up an onload handler as shown above.

2) use XMLHttpRequest and access the responseXML property:
    var httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange = function () {
      if (httpRequest.readyState == 4) {
        // access httpRequest.responseXML here
      }
    };
    httpRequest.open('GET', 'file.xml', true);
    httpRequest.send(null);


-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/