ACEXML 7.0.10
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
ACEXML_NamespaceSupport Class Reference

ACEXML_NamespaceSupport provides namespace management operation for an XML parser. More...

#include "ACEXML/common/NamespaceSupport.h"

Collaboration diagram for ACEXML_NamespaceSupport:
Collaboration graph
[legend]

Public Member Functions

 ACEXML_NamespaceSupport ()
 
 ~ACEXML_NamespaceSupport ()
 
int init ()
 
int declarePrefix (const ACEXML_Char *prefix, const ACEXML_Char *uri)
 
int getDeclaredPrefixes (ACEXML_STR_LIST &prefixes) const
 
const ACEXML_ChargetPrefix (const ACEXML_Char *uri) const
 
int getPrefixes (ACEXML_STR_LIST &prefixes) const
 
int getPrefixes (const ACEXML_Char *uri, ACEXML_STR_LIST &prefixes) const
 
const ACEXML_ChargetURI (const ACEXML_Char *prefix) const
 
int popContext ()
 
int processName (const ACEXML_Char *qName, const ACEXML_Char *&uri, const ACEXML_Char *&name, int is_attribute) const
 
int pushContext ()
 
int reset ()
 

Static Public Attributes

static const ACEXML_CharXMLNS_PREFIX = ACEXML_XMLNS_PREFIX_name
 
static const ACEXML_CharXMLNS = ACEXML_XMLNS_URI_name
 

Private Attributes

ACEXML_Namespace_Context_Stack ns_stack_
 
ACEXML_NS_CONTEXTeffective_context_
 

Detailed Description

ACEXML_NamespaceSupport provides namespace management operation for an XML parser.

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.

See also
ACEXML_Exception

Constructor & Destructor Documentation

◆ ACEXML_NamespaceSupport()

ACEXML_NamespaceSupport::ACEXML_NamespaceSupport ( )

Default constructor.

◆ ~ACEXML_NamespaceSupport()

ACEXML_NamespaceSupport::~ACEXML_NamespaceSupport ( )

Default destructor.

Member Function Documentation

◆ declarePrefix()

int ACEXML_NamespaceSupport::declarePrefix ( const ACEXML_Char prefix,
const ACEXML_Char uri 
)

Declare a Namespace prefix. Return -1 if the prefix was illegal or an internal error occurred. Return 0 if the prefix gets declared successfully, 1 if the prefix replaces an existing prefix definition.

◆ getDeclaredPrefixes()

int ACEXML_NamespaceSupport::getDeclaredPrefixes ( ACEXML_STR_LIST prefixes) const

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.

◆ getPrefix()

const ACEXML_Char * ACEXML_NamespaceSupport::getPrefix ( const ACEXML_Char uri) const

Return one of the prefixes mapped to a Namespace URI.

◆ getPrefixes() [1/2]

int ACEXML_NamespaceSupport::getPrefixes ( ACEXML_STR_LIST prefixes) const

Return all prefixes currently declared in the user-supplied list. @ Known bug: This function should only return user-defined prefixes.

◆ getPrefixes() [2/2]

int ACEXML_NamespaceSupport::getPrefixes ( const ACEXML_Char uri,
ACEXML_STR_LIST prefixes 
) const

Return all prefixes currently declared for a URI in the user-supplied list.

◆ getURI()

const ACEXML_Char * ACEXML_NamespaceSupport::getURI ( const ACEXML_Char prefix) const

Look up a prefix and get the currently-mapped Namespace URI.

◆ init()

int ACEXML_NamespaceSupport::init ( )

Initialize the namespace support object

◆ popContext()

int ACEXML_NamespaceSupport::popContext ( )

Revert to the previous namespace context.

◆ processName()

int ACEXML_NamespaceSupport::processName ( const ACEXML_Char qName,
const ACEXML_Char *&  uri,
const ACEXML_Char *&  name,
int  is_attribute 
) const

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.

◆ pushContext()

int ACEXML_NamespaceSupport::pushContext ( )

Start a new Namespace context. Prefixes defined in previous context are copied over to the new context.

◆ reset()

int ACEXML_NamespaceSupport::reset ( )

Reset this Namespace support object for reuse.

Member Data Documentation

◆ effective_context_

ACEXML_NS_CONTEXT* ACEXML_NamespaceSupport::effective_context_
private

The effective namespace context.

◆ ns_stack_

ACEXML_Namespace_Context_Stack ACEXML_NamespaceSupport::ns_stack_
private

Namespace Context stack. When we entering a new namespace context, the old context is duplicated and pushed into this stack.

◆ XMLNS

const ACEXML_Char * ACEXML_NamespaceSupport::XMLNS = ACEXML_XMLNS_URI_name
static

◆ XMLNS_PREFIX

const ACEXML_Char * ACEXML_NamespaceSupport::XMLNS_PREFIX = ACEXML_XMLNS_PREFIX_name
static

XMLNS default prefix and URI strings.


The documentation for this class was generated from the following files: