Unicorn XML Toolkit
Version 1.50.00

Namespace Sax
Class CNamespaceSupport

class CNamespaceSupport: public CInterface {
public:
    static const WCHAR m_szXmlns[];
public:
    CNamespaceSupport();
    ~CNamespaceSupport();
public:
    void Reset();
    void PushContext();
    void PopContext();
    bool DeclarePrefix(
        const WCHAR *pszPrefix, 
        const WCHAR *pszUri);
    const WCHAR **ProcessName(
        const WCHAR *pszQName,
        const WCHAR *arrParts[],
        bool bIsAttribute);
    const WCHAR *GetUri(const WCHAR *pszPrefix);
    XEnumeration GetPrefixes();
    const WCHAR *GetPrefix(const WCHAR *pszUri);
    XEnumeration GetPrefixes(const WCHAR *pszUri);
    XEnumeration GetDeclaredPrefixes();
    };
typedef XInterface<CNamespaceSupport> XNamespaceSupport;

The implementation of namespace processing logic.

This class encapsulates the logic of namespace processing: it tracks the declarations currently in force for each context and automatically processes qualified XML 1.0 names into their namespace parts; it can also be used in reverse for generating XML 1.0 from Namespaces.

Namespace support objects are reusable, but the reset method must be invoked between each session.

Note that this class is optimized for the use case where most elements do not contain namespace declarations: if the same prefix/URI mapping is repeated for each context (for example), this class will be somewhat less efficient.

Since:
1.00.00
Version:
1.50.00
Author:
C++ interfaces by Alexey Gokhberg; based on the original SAX2 specification by David Megginson
See Also:
CEnumeration
Constructor/Destructor Summary
CNamespaceSupport ();
����������Constructs the namespace support object.
~CNamespaceSupport ();
����������Destroys the namespace support object.

Function Summary
void Reset ();
����������Resets this namespace support object for reuse.
void PushContext ();
����������Starts a new namespace context.
void PopContext ();
����������Reverts to the previous namespace context.
bool DeclarePrefix (const WCHAR *pszPrefix, const WCHAR *pszUri);
����������Declares a namespace prefix.
const�WCHAR�** ProcessName (const WCHAR *pszQName, const WCHAR *arrParts[], bool bIsAttribute);
����������Processes a raw XML 1.0 name.
const�WCHAR�* GetUri (const WCHAR *pszPrefix);
����������Looks up a prefix and get the currently-mapped namespace URI.
XEnumeration GetPrefixes ();
����������Gets an enumeration of all prefixes currently declared.
const�WCHAR�* GetPrefix (const WCHAR *pszUri);
����������Gets one of the prefixes mapped to a namespace URI.
XEnumeration GetPrefixes (const WCHAR *pszUri);
����������Gets an enumeration of all prefixes currently declared for a URI.
XEnumeration GetDeclaredPrefixes ();
����������Gets an enumeration of all prefixes declared in this context.

Data Summary
const�WCHAR m_szXmlns [];
����������The XML namespace as a constant.

Constructor/Destructor Detail

CNamespaceSupport

CNamespaceSupport();

Constructs the namespace support object.

~CNamespaceSupport

~CNamespaceSupport();

Destroys the namespace support object.

Function Detail

Reset

void Reset();

Resets this namespace support object for reuse.

It is necessary to invoke this method before reusing the namespace support object for a new session.

PushContext

void PushContext();

Starts a new namespace context.

Normally, you should push a new context at the beginning of each XML element: the new context will automatically inherit the declarations of its parent context, but it will also keep track of which declarations were made within this context.

The namespace support object always starts with a base context already in force: in this context, only the "xml" prefix is declared.

PopContext

void PopContext();

Reverts to the previous namespace context.

Normally, you should pop the context at the end of each XML element. After popping the context, all namespace prefix mappings that were previously in force are restored.

You must not attempt to declare additional namespace prefixes after popping a context, unless you push another context first.

DeclarePrefix

bool DeclarePrefix(
    const WCHAR *pszPrefix, 
    const WCHAR *pszUri);

Declares a namespace prefix.

This method declares a prefix in the current namespace context; the prefix will remain in force until this context is popped, unless it is shadowed in a descendant context.

To declare a default namespace, use the empty string. The prefix must not be "xml" or "xmlns" .

Note that you must not declare a prefix after you've pushed and popped another namespace.

Note that there is an asymmetry in this library: while GetPrefix will not return the default "" prefix, even if you have declared one; to check for a default prefix, you have to look it up explicitly using GetUri . This asymmetry exists to make it easier to look up prefixes for attribute names, where the default prefix is not allowed.

Parameters:
pszPrefix - the prefix to declare, or null the empty string for the empty prefix
pszUri - the namespace URI to associate with the prefix
Returns:
true if the prefix was legal, false otherwise

ProcessName

const WCHAR **ProcessName(
    const WCHAR *pszQName,
    const WCHAR *arrParts[],
    bool bIsAttribute);

Processes a raw XML 1.0 name.

This method processes a raw XML 1.0 name in the current context by removing the prefix and looking it up among the prefixes currently declared. The return value will be the array supplied by the caller, filled in as follows:

arrParts[0]
The namespace URI, or an empty string if none is in use.
arrParts[1]
The local name (without prefix).
arrParts[2]
The original raw name.

If the raw name has a prefix that has not been declared, then the return value will be NULL .

Note that attribute names are processed differently than element names: an unprefixed element name will received the default namespace (if any), while an unprefixed element name will not.

Parameters:
pszQName - the raw XML 1.0 name to be processed
arrParts - an array supplied by the caller, capable of holding at least three members
bIsAttribute - a flag indicating whether this is an attribute name ( true ) or an element name ( false )
Returns:
the supplied array holding three strings representing the namespace URI (or empty string), the local name, and the raw XML 1.0 name; or NULL if there is an undeclared prefix

GetUri

const WCHAR *GetUri(const WCHAR *pszPrefix);

Looks up a prefix and get the currently-mapped namespace URI.

This method looks up the prefix in the current context. Use the empty string ( "" ) for the default namespace.

Parameters:
pszPrefix - the prefix to look up
Returns:
the associated namespace URI, or the empty string if the prefix is undeclared in this context

GetPrefixes

XEnumeration GetPrefixes();

Gets an enumeration of all prefixes currently declared.

NOTE: if there is a default prefix, it will not be returned in this enumeration; check for the default prefix using the GetUri with an argument of "" .

Returns:
the enumeration of all prefixes declared in the current context except for the empty (default) prefix

GetPrefix

const WCHAR *GetPrefix(const WCHAR *pszUri);

Gets one of the prefixes mapped to a namespace URI.

If more than one prefix is currently mapped to the same URI, this method will make an arbitrary selection; if you want all of the prefixes, use the GetPrefixes method instead.

NOTE: this will never return the empty (default) prefix; to check for a default prefix, use the GetUri method with an argument of "" .

Parameters:
pszUri - the namespace URI
Returns:
one of the prefixes currently mapped to the URI supplied, or the empty string if none is mapped or if the URI is assigned to the default namespace

GetPrefixes

XEnumeration GetPrefixes(const WCHAR *pszUri);

Gets an enumeration of all prefixes currently declared for a URI.

This method returns prefixes mapped to a specific namespace URI. The xml: prefix will be included. If you want only one prefix that's mapped to the namespace URI, and you don't care which one you get, use the GetPrefix method instead.

NOTE: the empty (default) prefix is never included in this enumeration; to check for the presence of a default namespace, use the GetUri method with an argument of "" .

Parameters:
pszUri - the namespace URI
Returns:
the enumeration of all prefixes declared in the current context

GetDeclaredPrefixes

XEnumeration GetDeclaredPrefixes();

Gets an enumeration of all prefixes declared in this context.

The empty (default) prefix will be included in this enumeration; note that this behaviour differs from that of GetPrefix and GetPrefixes .

Returns:
the enumeration of all prefixes declared in this context
Data Detail

m_szXmlns

static const WCHAR m_szXmlns[];

The XML namespace as a constant.

This is the namespace URI that is automatically mapped to the "xml" prefix.


Unicorn XML Toolkit
Version 1.50.00


This document was created using Unicorn DOC++.

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