|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/sax/NamespaceSupport.h"
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.
Here is a simple session:
String uri, localName; RefPtr<NamespaceSupport> rpSupport = new NamespaceSupport; rpSupport->pushContext(); rpSupport->declarePrefix("", "http://www.w3.org/1999/xhtml"); rpSupport->declarePrefix("dc", "http://www.purl.org/dc#"); rpSupport->processName("p", false, uri, localName); Console::cout() << OT_T("Namespace URI: ") << uri << endl; Console::cout() << OT_T("Local name: ") << localName << endl; rpSupport->processName("dc:title", false, uri, localName); Console::cout() << OT_T("Namespace URI: ") << uri << endl; Console::cout() << OT_T("Local name: ") << localName << endl; rpSupport->popContext();
Constructor/Destructor Summary | |
NamespaceSupport() Default constructor. |
Method Summary | |
bool |
declarePrefix(const String& prefix, const String& uri) Declare a Namespace prefix. |
PrefixList |
getDeclaredPrefixes() const Return a list of all prefixes declared in this context. |
String |
getPrefix(const String& uri) const Return one of the prefixes mapped to a Namespace URI. |
PrefixList |
getPrefixes() const Return a list of all prefixes currently declared. |
PrefixList |
getPrefixes(const String& uri) const Return a list of all prefixes currently declared for a URI. |
String |
getURI(const String& prefix) const Look up the URI associated with a prefix in this context. |
void |
popContext() Revert to the previous Namespace context. |
bool |
processName(const String& qName, bool bAttribute, String& retUri, String& retLocal) const Process a raw XML 1.0 name. |
void |
pushContext() Start a new Namespace context. |
void |
reset() Reset this Namespace support object for reuse. |
Methods inherited from class ot::ManagedObject |
addRef, getRefCount, onFinalRelease, operator=, release |
Public Static Data Members |
const String XMLNS
This is the Namespace URI that is automatically mapped to the xml prefix.
Typedefs |
typedef std::list< String > PrefixList
Constructor/Destructor Detail |
NamespaceSupport()
Method Detail |
bool declarePrefix(const String& prefix, const String& uri)
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 there is an asymmetry in this class: while getPrefix will not return the empty (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.
prefix
- uri
- PrefixList getDeclaredPrefixes() const
The empty (default) prefix will be included in this list; note that this behaviour differs from that of getPrefix() and getPrefixes().
String getPrefix(const String& uri) const
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 the empty string.
uri
- PrefixList getPrefixes() const
Note: if there is a default prefix, it will not be returned in this list; check for the default prefix using the getURI() method with an argument of the empty string.
PrefixList getPrefixes(const String& uri) const
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 list; to check for the presence of a default Namespace, use the getURI() method with an argument of the empty string.
uri
- String getURI(const String& prefix) const
prefix
- void popContext()
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 processName(const String& qName, bool bAttribute, String& retUri, String& retLocal) const
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 two return parameters: retUri and retLocal are filled in with the associated Namespace URI and local part respectively. A return value of false is returned if the qName contains a Namespace prefix which has not been declared.
Note that attribute names are processed differently to element names: an unprefixed element name will receive the default Namespace (if any), while an unprefixed element name will not.
qName
- bAttribute
- retUri
- retLocal
- void pushContext()
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 reset()
It is necessary to invoke this method before reusing the Namespace support object for a new session.
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |