CopperSpice API  1.9.1
QXmlNamespaceSupport Class Reference

The QXmlNamespaceSupport class is a helper class for XML readers which want to include namespace support. More...

Public Methods

 QXmlNamespaceSupport ()
 
 ~QXmlNamespaceSupport ()
 
void popContext ()
 
QString prefix (const QString &uri) const
 
QStringList prefixes () const
 
QStringList prefixes (const QString &uri) const
 
void processName (const QString &qname, bool isAttribute, QString &nsuri, QString &localname) const
 
void pushContext ()
 
void reset ()
 
void setPrefix (const QString &prefix, const QString &uri)
 
void splitName (const QString &qname, QString &prefix, QString &localname) const
 
QString uri (const QString &prefix) const
 

Detailed Description

The QXmlNamespaceSupport class is a helper class for XML readers which want to include namespace support.

You can set the prefix for the current namespace with setPrefix(), and get the list of current prefixes (or those for a given URI) with prefixes(). The namespace URI is available from uri(). Use pushContext() to start a new namespace context, and popContext() to return to the previous namespace context. Use splitName() or processName() to split a name into its prefix and local name.

See also
Namespace Support via Features

Constructor & Destructor Documentation

QXmlNamespaceSupport::QXmlNamespaceSupport ( )

Constructs a QXmlNamespaceSupport.

QXmlNamespaceSupport::~QXmlNamespaceSupport ( )

Destroys the QXmlNamespaceSupport.

Method Documentation

void QXmlNamespaceSupport::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.

See also
pushContext()
QString QXmlNamespaceSupport::prefix ( const QString uri) const

Returns one of the prefixes mapped to the namespace uri. If more than one prefix is currently mapped to the same URI, this method makes an arbitrary selection. If you want all of the prefixes, use prefixes() instead. To check for a default prefix call uri() and pass an empty string.

See also
setPrefix()
QStringList QXmlNamespaceSupport::prefixes ( ) const

Returns a list of all the prefixes currently declared. If there is a default prefix this method does not return it in the list. To check for the default prefix call uri() and pass an empty string.

QStringList QXmlNamespaceSupport::prefixes ( const QString uri) const

Returns a list of all prefixes currently declared for the namespace uri. The "xml" prefix is included. If you only want one prefix mapped to the namespace URI and you do not care which one you get, use the prefix() method instead.

The empty (default) prefix is never included in this list. To check for the presence of a default namespace call uri() and pass an empty string.

void QXmlNamespaceSupport::processName ( const QString qname,
bool  isAttribute,
QString nsuri,
QString localname 
) const

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 value for qname is the raw XML 1.0 name to be processed. The value for isAttribute is true if the name is an attribute name.

This method stores the namespace URI in nsuri (which will be set to an empty string if the raw name has an undeclared prefix), and stores the local name (without prefix) in localname (which will be set to an empty string if no namespace is in use).

Note that attribute names are processed differently than element names. An unprefixed element name gets the default namespace (if any), while an unprefixed attribute name does not.

void QXmlNamespaceSupport::pushContext ( )

Starts a new namespace context.

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

See also
popContext()
void QXmlNamespaceSupport::reset ( )

Resets this namespace support object ready for reuse.

void QXmlNamespaceSupport::setPrefix ( const QString prefix,
const QString uri 
)

Declares a prefix in the current namespace context to be an alias for the namespace uri. The prefix remains in force until this context is popped, unless it is shadowed in a descendant context.

There is an asymmetry in this library. The method prefix() does not return the default prefix, even if you have declared one. To check for a default prefix call uri() and pass an empty string. This asymmetry exists to make it easier to look up prefixes for attribute names, where the default prefix is not allowed.

See also
prefix()
void QXmlNamespaceSupport::splitName ( const QString qname,
QString prefix,
QString localname 
) const

Splits the name qname at the ':' and returns the prefix in prefix and the local name in localname.

See also
processName()
QString QXmlNamespaceSupport::uri ( const QString prefix) const

Looks up the prefix in the current context and returns the currently mapped namespace URI. Pass an empty string for the default namespace.