nsIDOMParser

IID:4f45513e-55e5-411c-a844-e899057026c1
Inherits From:nsISupports

The nsIDOMParser interface is a non-SAX interface that can be used to parse a string or byte stream containing XML or HTML content to a DOM document. Parsing is always synchronous - a document is always returned from the parsing methods. This is as opposed to loading and parsing with the XMLHttpRequest interface, which can be used for asynchronous (callback-based) loading.

This interface is implemented by the following components:


Properties

nsIURI baseURI

Set/Get the baseURI, may be needed when called from native code.


Methods

nsIDOMDocument parseFromBuffer ( arrayof PRUint8 buf , PRUint32 bufLen , char* contentType ) nsIDOMDocument parseFromStream ( nsIInputStream stream , char* charset , PRInt32 contentLength , char* contentType ) nsIDOMDocument parseFromString ( PRUnichar* str , char* contentType )

nsIDOMDocument parseFromBuffer ( arrayof PRUint8 buf , PRUint32 bufLen , char* contentType )

The buffer is parsed into a DOM document. The charset is determined from the xml entity decl.

Arguments:
buf: The octet array data to be parsed
bufLen: Length (in bytes) of the data
contentType: The content type of the data (see parseFromStream)

nsIDOMDocument parseFromStream ( nsIInputStream stream , char* charset , PRInt32 contentLength , char* contentType )

The byte stream passed in is parsed into a DOM document.

Not accessible from web content.

Arguments:
stream: The byte stream whose contents are parsed
charset: The character set that was used to encode the byte stream. NULL if not specified.
contentLength: The number of bytes in the input stream.
contentType: The content type of the string - either text/xml, application/xml, or application/xhtml+xml. Must not be NULL.

nsIDOMDocument parseFromString ( PRUnichar* str , char* contentType )

The string passed in is parsed into a DOM document.

Arguments:
str: The UTF16 string to be parsed
contentType: The content type of the string (see parseFromStream)

Reference documentation is generated from Mozilla's source.

Add a note User Contributed Notes
January 3, 2005, 2:16 pm mook dot moz at gmail dot com
If parseFromStream fails with "XML Parsing Error: no element found" at Line 1, Col 1 (as the output of parsing, without an exception being thrown), but parseFromString seems to work fine on the same content, try wrapping a nsIBufferedInputStream around the input stream. Some input streams don't implement nsIInputStream::readSegments, which seems to cause things to fail.

Copyright © 1999 - 2005 XULPlanet.com