WARNING: Most of this content (with the exception of the Mozilla 1.9 XPCOM reference) is very old, and can be expected to be out of date and possibly obsolete. For better XUL documentation, please visit the XUL hub at the Mozilla Developer Center.

nsIDocumentEncoder

IID:f85c5a20-258d-11db-a98b-0800200c9a66
Inherits From:nsISupports

Constants

Output only the selection (as opposed to the whole document).
PRUint32 OutputSelectionOnly = 1
Plaintext output: Convert html to plaintext that looks like the html. Implies wrap (except inside
), since html wraps.
HTML output: always do prettyprinting, ignoring existing formatting.
(Probably not well tested for HTML output.)
PRUint32 OutputFormatted = 2
Don't do prettyprinting of HTML. Don't do any wrapping that's not in the existing HTML source. This option overrides OutputFormatted if both are set.
PRUint32 OutputRaw = 4
Do not print html head tags.
PRUint32 OutputBodyOnly = 8
Wrap even if we're not doing formatted output (e.g. for text fields) XXXbz this doesn't seem to be used by all serializers... document? How does this interact with OutputFormatted/OutputRaw/OutputWrap/OutputFormatFlowed?
PRUint32 OutputPreformatted = 16
Output as though the content is preformatted (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag) XXXbz this doesn't seem to be used by all serializers... document? How does this interact with OutputFormatted/OutputRaw/OutputPreformatted/OutputFormatFlowed?
PRUint32 OutputWrap = 32
Output for format flowed (RFC 2646). This is used when converting to text for mail sending. This differs just slightly but in an important way from normal formatted, and that is that lines are space stuffed. This can't (correctly) be done later. XXXbz this doesn't seem to be used by all serializers... document? How does this interact with OutputFormatted/OutputRaw/OutputPreformatted/OutputWrap?
PRUint32 OutputFormatFlowed = 64
Convert links, image src, and script src to absolute URLs when possible
PRUint32 OutputAbsoluteLinks = 128
Attempt to encode entities standardized at W3C (HTML, MathML, etc). This is a catch-all flag for documents with mixed contents. Beware of interoperability issues. See below for other flags which might likely do what you want.
PRUint32 OutputEncodeW3CEntities = 256
LineBreak processing: if this flag is set than CR line breaks will be written. If neither this nor OutputLFLineBreak is set, then we will use platform line breaks. The combination of the two flags will cause CRLF line breaks to be written.
PRUint32 OutputCRLineBreak = 512
LineBreak processing: if this flag is set than LF line breaks will be written. If neither this nor OutputCRLineBreak is set, then we will use platform line breaks. The combination of the two flags will cause CRLF line breaks to be written.
PRUint32 OutputLFLineBreak = 1024
Output the content of noscript elements (only for serializing to plaintext).
PRUint32 OutputNoScriptContent = 2048
Output the content of noframes elements (only for serializing to plaintext).
PRUint32 OutputNoFramesContent = 4096
Don't allow any formatting nodes (e.g.
, ) inside a
.
This is used primarily by mail.
PRUint32 OutputNoFormattingInPre = 8192
Encode entities when outputting to a string. E.g. If set, we'll output   if clear, we'll output 0xa0. The basic set is just   & < > " for interoperability with older products that don't support α and friends.
PRUint32 OutputEncodeBasicEntities = 16384
Encode entities when outputting to a string. The Latin1 entity set additionally includes 8bit accented letters between 128 and 255.
PRUint32 OutputEncodeLatin1Entities = 32768
Encode entities when outputting to a string. The HTML entity set additionally includes accented letters, greek letters, and other special markup symbols as defined in HTML4.
PRUint32 OutputEncodeHTMLEntities = 65536
Normally   is replaced with a space character when encoding data as plain text, set this flag if that's not desired.
PRUint32 OutputPersistNBSP = 131072

Properties

readonly AString mimeType

The mime type preferred by the encoder. This piece of api was added because the copy encoder may need to switch mime types on you if you ask it to copy html that really represents plaintext content. Call this AFTER Init() and SetSelection() have both been called.


Methods

void encodeToStream ( nsIOutputStream stream ) AString encodeToString ( ) AString encodeToStringWithContext ( out AString contextString , out AString infoString ) void init ( nsIDOMDocument document , AString mimeType , PRUint32 flags ) void setCharset ( ACString charset ) void setContainerNode ( nsIDOMNode container ) void setNode ( nsIDOMNode node ) void setNodeFixup ( nsIDocumentEncoderNodeFixup fixup ) void setRange ( nsIDOMRange range ) void setSelection ( nsISelection selection ) void setWrapColumn ( PRUint32 wrapColumn )

void encodeToStream ( nsIOutputStream stream )

Encode the document and send the result to the nsIOutputStream.

Possible result codes are the stream errors which might have been encountered.

Arguments:
stream: Stream into which to encode.

AString encodeToString ( )

Encode the document into a string.

Returns:
The document encoded into a string.

AString encodeToStringWithContext ( out AString contextString , out AString infoString )

Encode the document into a string. Stores the extra context information into the two arguments.

Arguments:
contextString
infoString
Returns:
The document encoded as a string.

void init ( nsIDOMDocument document , AString mimeType , PRUint32 flags )

Initialize with a pointer to the document and the mime type.

Arguments:
document: Document to encode.
mimeType: MimeType to use. May also be set by SetMimeType.
flags: Flags to use while encoding. May also be set by SetFlags.

void setCharset ( ACString charset )

Documents typically have an intrinsic character set, but if no intrinsic value is found, the platform character set is used. This function overrides both the intrinisc and platform charset.

Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER

Arguments:
charset: Overrides the both the intrinsic or platform character set when encoding the document.

void setContainerNode ( nsIDOMNode container )

If the container is set to a non-null value, then its child nodes are used for encoding, otherwise the entire document or range or selection or node is encoded.

Arguments:
container: The node which child nodes will be encoded.

void setNode ( nsIDOMNode node )

If the node is set to a non-null value, then the node is used for encoding, otherwise the entire document or range or selection is encoded.

Arguments:
node: The node to encode.

void setNodeFixup ( nsIDocumentEncoderNodeFixup fixup )

Set the fixup object associated with node persistence.

Arguments:
fixup: The fixup object.

void setRange ( nsIDOMRange range )

If the range is set to a non-null value, then the range is used for encoding, otherwise the entire document or selection is encoded.

Arguments:
range: The range to encode.

void setSelection ( nsISelection selection )

If the selection is set to a non-null value, then the selection is used for encoding, otherwise the entire document is encoded.

Arguments:
selection: The selection to encode.

void setWrapColumn ( PRUint32 wrapColumn )

Set a wrap column. This may have no effect in some types of encoders.

Arguments:
wrapColumn: Column to which to wrap.

Reference documentation is generated from Mozilla's source.