Unicorn XML Toolkit
Version 1.50.00

Namespace Xml
Class CXmlWriter

class CXmlWriter: public Sax::CContentHandler {
public:
    CXmlWriter(CToolkitBase *pToolkitBase);
    ~CXmlWriter();
public:
    void SetDocumentLocator(Sax::CLocator *pLocator);
    void StartDocument();
    void EndDocument();
    void StartPrefixMapping(
        const WCHAR *pszPrefix,
        const WCHAR *pszUri);
    void EndPrefixMapping(const WCHAR *pszPrefix);
    void StartElement(
        const WCHAR *pszUri,
        const WCHAR *pszLocalName,
        const WCHAR *pszQName,
        Sax::CAttributes *pAtts);
    void EndElement(
        const WCHAR *pszUri,
        const WCHAR *pszLocalName,
        const WCHAR *pszQName);
    void Characters(const WCHAR *pCh, int nLength);
    void IgnorableWhitespace(const WCHAR *pCh, int nLength);
    void ProcessingInstruction(
        const WCHAR *pszTarget,
        const WCHAR *pszData);
    void SkippedEntity(const WCHAR *pszName);
public:
    void SetUri(const WCHAR *pszUri);
    bool GetUri(CString &strUri);
    void SetByteStream(IStream *pByteStream);
    bool GetByteStream(IStream *&pByteStream);
    void SetCharacterStream(IUnicodeStream *pCharacterStream);
    bool GetCharacterStream(IUnicodeStream *&pCharacterStream);
    void SetNamespaces(bool bNamespaces);
    bool GetNamespaces(bool &bNamespaces);
    void SetMethod(const WCHAR *pszMethod);
    bool GetMethod(CString &strMethod);
    void SetVersion(const WCHAR *pszVersion);
    bool GetVersion(CString &strVersion);
    void SetEncoding(const WCHAR *pszEncoding);
    bool GetEncoding(CString &strEncoding);
    void SetOmitXmlDeclaration(bool bOmitXmlDeclaration);
    bool GetOmitXmlDeclaration(bool &bOmitXmlDeclaration);
    void SetStandalone(bool bStandalone);
    bool GetStandalone(bool &bStandalone);
    void SetDoctypePublic(const WCHAR *pszDoctypePublic);
    bool GetDoctypePublic(CString &strDoctypePublic);
    void SetDoctypeSystem(const WCHAR *pszDoctypeSystem);
    bool GetDoctypeSystem(CString &strDoctypeSystem);
    void SetIndent(bool bIndent);
    bool GetIndent(bool &bIndent);
    void SetMediaType(const WCHAR *pszMediaType);
    bool GetMediaType(CString &strMediaType);
    };
typedef XInterface<CXmlWriter> XXmlWriter;

The general-purpose XML writer designed to transform SAX content event streams into their text-based representation using XML, HTML, or plain text formats.

XML writer is represented as the subclass of SAX content handler (see Sax::CContentHandler ). It accepts the stream of XML content events as input. The application programmer must specify whether the input stream is expected to perform namespace processing (see Sax for the detailed discussion of the namespace processing in SAX).

XML writer generates the output text stream in the specified format and sends it to a specified target URI, a byte stream, or a Unicode character stream.

XML writer engine is modeled after the output facility specified in XSL Transformations (XSLT) Version 1.0.

In particular, every XML writer owns a collection of properties corresponding to various attributes specified for XSLT xsl:output element. For each property the CXmlWriter class provides a pair of member functions designed to get or set the property value. Each property may be assigned a particular value, or may be undefined.

Following is the complete list of writer properties. Refer to XSL Transformations (XSLT) Version 1.0 for the detailed description of semantics of these properties.

Additionally, there are few writer properties which have no equivalent in XSLT:

Only one target may be specified, that is, the target URI, target byte stream, and target Unicode stream properties are mutually exclusive.

Since:
1.50.00
Version:
1.50.00
Author:
Alexey Gokhberg
See Also:
CToolkitBase, Sax::CAttributes, Sax::CLocator
Constructor/Destructor Summary
CXmlWriter (CToolkitBase *pToolkitBase);
����������Constructs the XML writer.
~CXmlWriter ();
����������Destroys the XML writer.

Function Summary
void SetDocumentLocator (Sax::CLocator *pLocator);
����������Receives an object for locating the origin of SAX content events.
void StartDocument ();
����������Receives notification of the beginning of a document.
void EndDocument ();
����������Receives notification of the end of a document.
void StartPrefixMapping (const WCHAR *pszPrefix, const WCHAR *pszUri);
����������Begins the scope of a namespace prefix-URI mapping.
void EndPrefixMapping (const WCHAR *pszPrefix);
����������Ends the scope of a namespace prefix-URI mapping.
void StartElement (const WCHAR *pszUri, const WCHAR *pszLocalName, const WCHAR *pszQName, Sax::CAttributes *pAtts);
����������Receives notification of the beginning of an element.
void EndElement (const WCHAR *pszUri, const WCHAR *pszLocalName, const WCHAR *pszQName);
����������Receives notification of the end of an element.
void Characters (const WCHAR *pCh, int nLength);
����������Receives notification of character data.
void IgnorableWhitespace (const WCHAR *pCh, int nLength);
����������Receives notification of ignorable whitespace in element content.
void ProcessingInstruction (const WCHAR *pszTarget, const WCHAR *pszData);
����������Receives notification of a processing instruction.
void SkippedEntity (const WCHAR *pszName);
����������Receives notification of a skipped entity.
void SetUri (const WCHAR *pszUri);
����������Sets the target URI.
bool GetUri (CString &strUri);
����������Queries the target URI.
void SetByteStream (IStream *pByteStream);
����������Sets the target byte stream.
bool GetByteStream (IStream *&pByteStream);
����������Queries the target byte stream.
void SetCharacterStream (IUnicodeStream *pCharacterStream);
����������Sets the target Unicode character stream.
bool GetCharacterStream (IUnicodeStream *&pCharacterStream);
����������Queries the target Unicode character stream.
void SetNamespaces (bool bNamespaces);
����������Sets the namespace processing indicator.
bool GetNamespaces (bool &bNamespaces);
����������Queries the namespace processing indicator.
void SetMethod (const WCHAR *pszMethod);
����������Sets the name of the output method.
bool GetMethod (CString &strMethod);
����������Queries the name of the output method.
void SetVersion (const WCHAR *pszVersion);
����������Sets the version of the output method.
bool GetVersion (CString &strVersion);
����������Queries the version of the output method.
void SetEncoding (const WCHAR *pszEncoding);
����������Sets the preferred character encoding.
bool GetEncoding (CString &strEncoding);
����������Queries the preferred character encoding.
void SetOmitXmlDeclaration (bool bOmitXmlDeclaration);
����������Sets the omit XML declaration indicator.
bool GetOmitXmlDeclaration (bool &bOmitXmlDeclaration);
����������Queries the omit XML declaration indicator.
void SetStandalone (bool bStandalone);
����������Sets the standalone indicator.
bool GetStandalone (bool &bStandalone);
����������Queries the standalone indicator.
void SetDoctypePublic (const WCHAR *pszDoctypePublic);
����������Sets the document type public identifier.
bool GetDoctypePublic (CString &strDoctypePublic);
����������Queries the document type system identifier.
void SetDoctypeSystem (const WCHAR *pszDoctypeSystem);
����������Sets the document type system identifier.
bool GetDoctypeSystem (CString &strDoctypeSystem);
����������Queries the document type public identifier.
void SetIndent (bool bIndent);
����������Sets the indent indicator.
bool GetIndent (bool &bIndent);
����������Queries the indent indicator.
void SetMediaType (const WCHAR *pszMediaType);
����������Sets the media type.
bool GetMediaType (CString &strMediaType);
����������Queries the media type.

Constructor/Destructor Detail

CXmlWriter

CXmlWriter(CToolkitBase *pToolkitBase);

Constructs the XML writer.

Parameters:
pToolkitBase - the master toolkit base

~CXmlWriter

~CXmlWriter();

Destroys the XML writer.

Function Detail

SetDocumentLocator

void SetDocumentLocator(Sax::CLocator *pLocator);

Receives an object for locating the origin of SAX content events.

Parameters:
pLocator - an object that can return the location of any SAX content event

StartDocument

void StartDocument();

Receives notification of the beginning of a document.

EndDocument

void EndDocument();

Receives notification of the end of a document.

StartPrefixMapping

void StartPrefixMapping(
    const WCHAR *pszPrefix,
    const WCHAR *pszUri);

Begins the scope of a namespace prefix-URI mapping.

Parameters:
pszPrefix - the namespace prefix being declared
pszUri - the namespace URI the prefix is mapped to

EndPrefixMapping

void EndPrefixMapping(const WCHAR *pszPrefix);

Ends the scope of a namespace prefix-URI mapping.

Parameters:
pszPrefix - the prefix that was being mapped

StartElement

void StartElement(
    const WCHAR *pszUri,
    const WCHAR *pszLocalName,
    const WCHAR *pszQName,
    Sax::CAttributes *pAtts);

Receives notification of the beginning of an element.

Parameters:
pszUri - the namespace URI, or the empty string if the element has no namespace URI or if namespace processing is not being performed
pszLocalName - the local name (without prefix), or the empty string if namespace processing is not being performed
pszQName - the qualified name (with prefix), or the empty string if qualified names are not available
pAtts - the list of attributes attached to the element. If there are no attributes, it shall be empty.

EndElement

void EndElement(
    const WCHAR *pszUri,
    const WCHAR *pszLocalName,
    const WCHAR *pszQName);

Receives notification of the end of an element.

Parameters:
pszUri - the namespace URI, or the empty string if the element has no namespace URI or if namespace processing is not being performed
pszLocalName - the local name (without prefix), or the empty string if namespace processing is not being performed
pszQName - the qualified name (with prefix), or the empty string if qualified names are not available

Characters

void Characters(const WCHAR *pCh, int nLength);

Receives notification of character data.

Parameters:
pCh - the array of characters from the XML document
nLength - the number of characters to read from the array

IgnorableWhitespace

void IgnorableWhitespace(const WCHAR *pCh, int nLength);

Receives notification of ignorable whitespace in element content.

Parameters:
pCh - the array of characters from the XML document
nLength - the number of characters to read from the array

ProcessingInstruction

void ProcessingInstruction(
    const WCHAR *pszTarget,
    const WCHAR *pszData);

Receives notification of a processing instruction.

Parameters:
pszTarget - the processing instruction target
pszData - the processing instruction data, or the empty string if none was supplied

SkippedEntity

void SkippedEntity(const WCHAR *pszName);

Receives notification of a skipped entity.

Parameters:
pszName - the name of the skipped entity

SetUri

void SetUri(const WCHAR *pszUri);

Sets the target URI.

Parameters:
pszUri - the string representing the target URI

GetUri

bool GetUri(CString &strUri);

Queries the target URI.

Parameters:
strUri - on return, the string representing the target URI, if defined
Returns:
true if the target URI is defined; false otherwise

SetByteStream

void SetByteStream(IStream *pByteStream);

Sets the target byte stream.

Parameters:
pByteStream - the target byte stream

GetByteStream

bool GetByteStream(IStream *&pByteStream);

Queries the target byte stream.

Parameters:
pByteStream - on return, the target byte stream, if defined
Returns:
true if the target byte stream is defined; false otherwise

SetCharacterStream

void SetCharacterStream(IUnicodeStream *pCharacterStream);

Sets the target Unicode character stream.

Parameters:
pCharacterStream - the target Unicode character stream

GetCharacterStream

bool GetCharacterStream(IUnicodeStream *&pCharacterStream);

Queries the target Unicode character stream.

Parameters:
pCharacterStream - on return, the target Unicode character stream, if defined
Returns:
true if the target Unicode character stream is defined; false otherwise

SetNamespaces

void SetNamespaces(bool bNamespaces);

Sets the namespace processing indicator.

Parameters:
bNamespaces - the boolean namespace processing indicator

GetNamespaces

bool GetNamespaces(bool &bNamespaces);

Queries the namespace processing indicator.

Parameters:
bNamespaces - on return, the boolean namespace processing indicator, if defined
Returns:
true if the namespace processing indicator is defined; false otherwise

SetMethod

void SetMethod(const WCHAR *pszMethod);

Sets the name of the output method.

The supported method names are "xml" , "html" , and "text" .

Parameters:
pszMehod - the name of the output method

GetMethod

bool GetMethod(CString &strMethod);

Queries the name of the output method.

Parameters:
strMethod - on return, the name of the output method, if defined
Returns:
true if the name of the output method is defined; false otherwise

SetVersion

void SetVersion(const WCHAR *pszVersion);

Sets the version of the output method.

Parameters:
pszVersion - the version of the output method

GetVersion

bool GetVersion(CString &strVersion);

Queries the version of the output method.

Parameters:
strVersion - on return, the version of the output method, if defined
Returns:
true if the version of the output method is defined, false otherwise

SetEncoding

void SetEncoding(const WCHAR *pszEncoding);

Sets the preferred character encoding.

See Unicode for the list of supported encoding names.

Parameters:
pszEncoding - the string representing the encoding name

GetEncoding

bool GetEncoding(CString &strEncoding);

Queries the preferred character encoding.

Parameters:
strEncoding - on return, the string representing the encoding name, if defined
Returns:
true if the encoding name is defined; false otherwise

SetOmitXmlDeclaration

void SetOmitXmlDeclaration(bool bOmitXmlDeclaration);

Sets the omit XML declaration indicator.

Parameters:
bOmitXmlDeclaration - the boolean omit XML declaration indicator

GetOmitXmlDeclaration

bool GetOmitXmlDeclaration(bool &bOmitXmlDeclaration);

Queries the omit XML declaration indicator.

Parameters:
bOmitXmlDeclaration - on return, the boolean XML declaration indicator, if defined
Returns:
true if the omit XML declaration indicator is defined; false otherwise

SetStandalone

void SetStandalone(bool bStandalone);

Sets the standalone indicator.

Parameters:
bStandalone - the boolean standalone indicator

GetStandalone

bool GetStandalone(bool &bStandalone);

Queries the standalone indicator.

Parameters:
bStandalone - on return, the boolean standalone indicator, if defined
Returns:
true if the standalone indicator is defined; false otherwise

SetDoctypePublic

void SetDoctypePublic(const WCHAR *pszDoctypePublic);

Sets the document type public identifier.

Parameters:
pszDoctypePublic - the string representing the document type public identifier

GetDoctypePublic

bool GetDoctypePublic(CString &strDoctypePublic);

Queries the document type system identifier.

Parameters:
strDoctypePublic - on return, the string representing the document type system identifier, if defined
Returns:
true if the document system identifier is defined; false otherwise

SetDoctypeSystem

void SetDoctypeSystem(const WCHAR *pszDoctypeSystem);

Sets the document type system identifier.

Parameters:
pszDoctypeSystem - the string representing the document type system identifier

GetDoctypeSystem

bool GetDoctypeSystem(CString &strDoctypeSystem);

Queries the document type public identifier.

Parameters:
strDoctypeSystem - on return, the string representing the document type public identifier, if defined
Returns:
true if the document system identifier is defined; false otherwise

SetIndent

void SetIndent(bool bIndent);

Sets the indent indicator.

Parameters:
bIndent - the boolean indent indicator

GetIndent

bool GetIndent(bool &bIndent);

Queries the indent indicator.

Parameters:
bIndent - on return, the boolean indent indicator, if defined
Returns:
true if the indent indicator is defined; false otherwise

SetMediaType

void SetMediaType(const WCHAR *pszMediaType);

Sets the media type.

Parameters:
strMediaType - the string representing the media type

GetMediaType

bool GetMediaType(CString &strMediaType);

Queries the media type.

Parameters:
strMediaType - on return, the string representing the media type, if defined
Returns:
true if the media type is defined; false otherwise

Unicorn XML Toolkit
Version 1.50.00


This document was created using Unicorn DOC++.

Copyright 1999-2001 Unicorn Enterprises SA.
All Rights Reserved.