DOMParser
From MDC
DOMParser can be used to parse strings and streams of XML text. It can't be used to parse HTML "tag soup". DOMParser is available to unprivileged scripts.
Note:
DOMParser is mainly useful for applications and extensions based on Mozilla platform. While it's available to web pages, it's not part of any standard and level of support in other browsers is unknown.Contents |
[edit] DOMParser changes in Firefox 3
Note: This section covers changes introduced to
DOMParser in Gecko 1.9.- When a
DOMParseris instantiated by callingnew DOMParser(), it inherits the calling code's principal and thedocumentURIandbaseURIof the window the constructor came from. - If the caller has UniversalXPConnect privileges, it can pass parameters to
new DOMParser(). If fewer than three parameters are passed, the remaining parameters will default tonull.- The first parameter is the principal to use; this overrides the default principal normally inherited.
- The second parameter is the
documentURIto use. - The third parameter is the
baseURIto use.
- If you instantiate a
DOMParserby callingcreateInstance(), and you don't call theDOMParser'sinit()method, attempting to initiate a parsing operation will automatically callinit()on theDOMParserwith a null principal andnullpointers fordocumentURIandbaseURI.
[edit] Error handling
Note that if the parsing process failed, DOMParser currently does not throw an exception, but instead returns an error document (see bug 45566):
<parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml"> (error description) <sourcetext>(a snipper of the source XML)</sourcetext> </parsererror>
[edit] Example
var parser = new DOMParser(); var doc = parser.parseFromString(aStr, "text/xml");
[edit] See also
- Reference (XULPlanet)
- Parsing and serializing XML
- Parsing and serializing XML (XULPlanet)
- XMLHttpRequest
- XMLSerializer