#include "ACEXML/common/NamespaceSupport.h"
Collaboration diagram for ACEXML_NamespaceSupport:
Public Methods | |
ACEXML_NamespaceSupport (void) | |
Default constructor. More... | |
~ACEXML_NamespaceSupport (void) | |
Default destructor. More... | |
int | declarePrefix (const ACEXML_Char *prefix, const ACEXML_Char *uri) |
Declare a Namespace prefix. More... | |
int | getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const |
Return all prefixes declared in current context in the user-supplied list prefixes. More... | |
const ACEXML_Char * | getPrefix (const ACEXML_Char *uri) const |
Return one of the prefixes mapped to a Namespace URI. More... | |
int | getPrefixes (ACEXML_STR_LIST &prefixes) const |
Return all prefixes currently declared in the user-supplied list. More... | |
int | getPrefixes (const ACEXML_Char *uri, ACEXML_STR_LIST &prefixes) const |
Return all prefixes currently declared for a URI in the user-supplied list. More... | |
const ACEXML_Char * | getURI (const ACEXML_Char *prefix) const |
Look up a prefix and get the currently-mapped Namespace URI. More... | |
int | popContext (void) |
Revert to the previous namespace context. More... | |
int | processName (const ACEXML_Char *qName, const ACEXML_Char *&uri, const ACEXML_Char *&name, int is_attribute) const |
Process a raw XML 1.0 name. More... | |
int | pushContext (void) |
Start a new Namespace context. More... | |
int | reset (void) |
Reset this Namespace support object for reuse. More... | |
Static Public Attributes | |
const ACEXML_Char * | XMLNS_PREFIX = ACEXML_XMLNS_PREFIX_name |
XMLNS default prefix and URI strings. More... | |
const ACEXML_Char * | XMLNS = ACEXML_XMLNS_URI_name |
Private Attributes | |
ACEXML_Namespace_Context_Stack | ns_stack_ |
Namespace Context stack. More... | |
ACEXML_NS_CONTEXT * | effective_context_ |
The effective namespace context. More... |
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 (in Java :-p):
String parts[] = new String[3]; NamespaceSupport support = new NamespaceSupport(); support.pushContext(); support.declarePrefix("", "http://www.w3.org/1999/xhtml"); support.declarePrefix("dc", "http://www.purl.org/dc#"); String parts[] = support.processName("p", parts, false); System.out.println("Namespace URI: " + parts[0]); System.out.println("Local name: " + parts[1]); System.out.println("Raw name: " + parts[2]); String parts[] = support.processName("dc:title", parts, false); System.out.println("Namespace URI: " + parts[0]); System.out.println("Local name: " + parts[1]); System.out.println("Raw name: " + parts[2]); support.popContext();
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.
|
Default constructor.
|
|
Default destructor.
|
|
Declare a Namespace prefix. Return -1 if the prefix was illegal or an internal error occured. Return 0 if the prefix gets declared successfully, 1 if the prefix replaces an existing prefix definition. |
|
Return all prefixes declared in current context in the user-supplied list prefixes. It is user's reponsibility to ensure the list was empty originally. |
|
Return one of the prefixes mapped to a Namespace URI.
|
|
Return all prefixes currently declared for a URI in the user-supplied list.
|
|
Return all prefixes currently declared in the user-supplied list. @ Known bug: This function should only return user-defined prefixes. |
|
Look up a prefix and get the currently-mapped Namespace URI.
|
|
Revert to the previous namespace context.
|
|
Process a raw XML 1.0 name. qName is the raw XML name we want to parse, uri contains the URI string of the raw name. It points to a null string if the namespace is not valid or there's no namespace defined. name contains the original name without the prefix. is_attribute specifies whether the name is an attribute or not. Attributes have different scoping rules from elements. |
|
Start a new Namespace context. Prefixes defined in previous context are copied over to the new context. |
|
Reset this Namespace support object for reuse.
|
|
The effective namespace context.
|
|
Namespace Context stack. When we entering a new namespace context, the old context is duplicated and pushed into this stack. |
|
|
|
XMLNS default prefix and URI strings.
|