|
Unicorn XML Toolkit Version 1.50.00 |
|||||||||
� PREV CLASS �� NEXT CLASS | FRAMES��NO FRAMES | |||||||||
SUMMARY: � CONSTR �|� FUNCTION �|� DATA | DETAIL: � CONSTR �|� FUNCTION �|� DATA |
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.
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();
Constructs the namespace support object.
~CNamespaceSupport();
Destroys the namespace support object.
Function Detail |
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.
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.
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.
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.
pszPrefix
- the prefix to declare, or null the empty
string for the empty prefixpszUri
- the namespace URI to associate with the prefixtrue
if the prefix was legal,
false
otherwiseconst 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]
arrParts[1]
arrParts[2]
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.
pszQName
- the raw XML 1.0 name to be processedarrParts
- an array supplied by the caller, capable of
holding at least three membersbIsAttribute
- a flag indicating whether this is an
attribute name (
true
)
or an element name (
false
)NULL
if there
is an undeclared prefixconst 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.
pszPrefix
- the prefix to look upXEnumeration 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
""
.
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
""
.
pszUri
- the namespace URIXEnumeration 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
""
.
pszUri
- the namespace URIXEnumeration 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
.
Data Detail |
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 |
|||||||||
� PREV CLASS �� NEXT CLASS | FRAMES��NO FRAMES | |||||||||
SUMMARY: � CONSTR �|� FUNCTION �|� DATA | DETAIL: � CONSTR �|� FUNCTION �|� DATA |