libSBML C API  5.18.0
XMLNamespaces_t Class Reference

Detailed Description

An XML Namespace.

This class of objects is defined by libSBML only and has no direct equivalent in terms of SBML components. This class is not prescribed by the SBML specifications, although it is used to implement features defined in SBML.

This class serves to organize functionality for tracking XML namespaces in a document or data stream. The namespace declarations are stored as a list of pairs of XML namespace URIs and prefix strings. These correspond to the parts of a namespace declaration on an XML element. For example, in the following XML fragment,

<annotation>
    <mysim:nodecolors xmlns:mysim="urn:lsid:mysim.org"
         mysim:bgcolor="green" mysim:fgcolor="white"/>
</annotation>

there is one namespace declaration. Its URI is urn:lsid:mysim.org and its prefix is mysim. This pair could be stored as one item in an XMLNamespaces_t list.

XMLNamespaces_t provides various methods for manipulating the list of prefix-URI pairs. Individual namespaces stored in a given XMLNamespace object instance can be retrieved based on their index using XMLNamespaces_t::getPrefix(int index), or by their characteristics such as their URI or position in the list.

Examples:
addingEvidenceCodes_2.c, createExampleSBML.c, and spec_example1.c.

Public Member Functions

LIBLAX_EXTERN int XMLNamespaces_add (XMLNamespaces_t *ns, const char *uri, const char *prefix)
 Appends an XML namespace prefix/URI pair to this XMLNamespaces_t structure. More...
 
LIBLAX_EXTERN int XMLNamespaces_clear (XMLNamespaces_t *ns)
 Clears this XMLNamespaces_t structure. More...
 
LIBLAX_EXTERN XMLNamespaces_tXMLNamespaces_clone (const XMLNamespaces_t *ns)
 Creates a deep copy of the given XMLNamespaces_t structure. More...
 
LIBLAX_EXTERN XMLNamespaces_tXMLNamespaces_create (void)
 Creates a new empty XMLNamespaces_t structure. More...
 
LIBLAX_EXTERN void XMLNamespaces_free (XMLNamespaces_t *ns)
 Frees the given XMLNamespaces_t structure. More...
 
LIBLAX_EXTERN int XMLNamespaces_getIndex (const XMLNamespaces_t *ns, const char *uri)
 Lookup the index of an XML namespace declaration by URI. More...
 
LIBLAX_EXTERN int XMLNamespaces_getIndexByPrefix (const XMLNamespaces_t *ns, const char *prefix)
 Look up the index of an XML namespace declaration by prefix. More...
 
LIBLAX_EXTERN int XMLNamespaces_getLength (const XMLNamespaces_t *ns)
 Returns the total number of URI-and-prefix pairs stored in this particular XMLNamespaces_t instance. More...
 
LIBLAX_EXTERN int XMLNamespaces_getNumNamespaces (const XMLNamespaces_t *ns)
 Returns the total number of URI-and-prefix pairs stored in this particular XMLNamespaces_t instance. More...
 
LIBLAX_EXTERN char * XMLNamespaces_getPrefix (const XMLNamespaces_t *ns, int index)
 Look up the prefix of an XML namespace declaration by its position. More...
 
LIBLAX_EXTERN char * XMLNamespaces_getPrefixByURI (const XMLNamespaces_t *ns, const char *uri)
 Look up the prefix of an XML namespace declaration by its URI. More...
 
LIBLAX_EXTERN char * XMLNamespaces_getURI (const XMLNamespaces_t *ns, int index)
 Look up the URI of an XML namespace declaration by its position. More...
 
LIBLAX_EXTERN char * XMLNamespaces_getURIByPrefix (const XMLNamespaces_t *ns, const char *prefix)
 Look up the URI of an XML namespace declaration by its prefix. More...
 
LIBLAX_EXTERN int XMLNamespaces_hasNS (const XMLNamespaces_t *ns, const char *uri, const char *prefix)
 Predicate returning 1 (true) or 0 (false) depending on whether an XML Namespace with the given URI is contained in this XMLNamespaces_t list. More...
 
LIBLAX_EXTERN int XMLNamespaces_hasPrefix (const XMLNamespaces_t *ns, const char *prefix)
 Predicate returning 1 (true) or 0 (false) depending on whether an XML Namespace the given prefix is contained in this XMLNamespaces_t list. More...
 
LIBLAX_EXTERN int XMLNamespaces_hasURI (const XMLNamespaces_t *ns, const char *uri)
 Predicate returning 1 (true) or 0 (false) depending on whether an XML Namespace with the given URI is contained in this XMLNamespaces_t list. More...
 
LIBLAX_EXTERN int XMLNamespaces_isEmpty (const XMLNamespaces_t *ns)
 Predicate returning 1 (true) or 0 (false) depending on whether this XMLNamespaces_t list is empty. More...
 
LIBLAX_EXTERN int XMLNamespaces_remove (XMLNamespaces_t *ns, int index)
 Removes an XML Namespace stored in the given position of this list. More...
 
LIBLAX_EXTERN int XMLNamespaces_removeByPrefix (XMLNamespaces_t *ns, const char *prefix)
 Removes an XML Namespace with the given prefix. More...
 

Member Function Documentation

LIBLAX_EXTERN int XMLNamespaces_add ( XMLNamespaces_t ns,
const char *  uri,
const char *  prefix 
)

Appends an XML namespace prefix/URI pair to this XMLNamespaces_t structure.

Parameters
nsthe XMLNamespaces_t structure.
uria string, the uri for the namespace.
prefixa string, the prefix for the namespace.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
Examples:
addingEvidenceCodes_2.c, createExampleSBML.c, and spec_example1.c.
LIBLAX_EXTERN int XMLNamespaces_clear ( XMLNamespaces_t ns)

Clears this XMLNamespaces_t structure.

Parameters
nsXMLNamespaces_t structure.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
LIBLAX_EXTERN XMLNamespaces_t * XMLNamespaces_clone ( const XMLNamespaces_t ns)

Creates a deep copy of the given XMLNamespaces_t structure.

Parameters
nsthe XMLNamespaces_t structure to be copied.
Returns
a (deep) copy of the given XMLNamespaces_t structure.
LIBLAX_EXTERN XMLNamespaces_t * XMLNamespaces_create ( void  )

Creates a new empty XMLNamespaces_t structure.

Examples:
addingEvidenceCodes_2.c, and spec_example1.c.
LIBLAX_EXTERN void XMLNamespaces_free ( XMLNamespaces_t ns)

Frees the given XMLNamespaces_t structure.

Parameters
nsXMLNamespaces_t structure to be freed.
LIBLAX_EXTERN int XMLNamespaces_getIndex ( const XMLNamespaces_t ns,
const char *  uri 
)

Lookup the index of an XML namespace declaration by URI.

Parameters
nsthe XMLNamespaces_t structure.
uria string, uri of the required namespace.
Returns
the index of the given declaration, or -1 if not present.
LIBLAX_EXTERN int XMLNamespaces_getIndexByPrefix ( const XMLNamespaces_t ns,
const char *  prefix 
)

Look up the index of an XML namespace declaration by prefix.

Parameters
nsthe XMLNamespaces_t structure.
prefixa string, prefix of the required namespace.
Returns
the index of the given declaration, or -1 if not present.
LIBLAX_EXTERN int XMLNamespaces_getLength ( const XMLNamespaces_t ns)

Returns the total number of URI-and-prefix pairs stored in this particular XMLNamespaces_t instance.

Parameters
nsthe XMLNamespaces_t structure.
Returns
the number of namespaces in this list.
LIBLAX_EXTERN int XMLNamespaces_getNumNamespaces ( const XMLNamespaces_t ns)

Returns the total number of URI-and-prefix pairs stored in this particular XMLNamespaces_t instance.

This function is an alias for getLength introduced for consistency with other XML classes.

Parameters
nsthe XMLNamespaces_t structure.
Returns
the number of namespaces in this list.
LIBLAX_EXTERN char * XMLNamespaces_getPrefix ( const XMLNamespaces_t ns,
int  index 
)

Look up the prefix of an XML namespace declaration by its position.

An XMLNamespaces_t structure stores a list of pairs of namespaces and their prefixes. This method returns the prefix of the nth element in that list (if it exists). Callers should use XMLAttributes_getLength() first to find out how many namespaces are stored in the list.

Parameters
nsthe XMLNamespaces_t structure.
indexan integer, position of the sought-after prefix.
Returns
the prefix of an XML namespace declaration in this list (by position), or an empty string if the index is out of range
See also
XMLNamespaces_getLength()
LIBLAX_EXTERN char * XMLNamespaces_getPrefixByURI ( const XMLNamespaces_t ns,
const char *  uri 
)

Look up the prefix of an XML namespace declaration by its URI.

An XMLNamespaces_t structure stores a list of pairs of namespaces and their prefixes. This method returns the prefix for a pair that has the given uri.

Parameters
nsthe XMLNamespaces_t structure.
uria string, the URI of the prefix being sought.
Returns
the prefix of an XML namespace declaration given its URI, or an empty string if no such uri exists in this XMLNamespaces_t structure
LIBLAX_EXTERN char * XMLNamespaces_getURI ( const XMLNamespaces_t ns,
int  index 
)

Look up the URI of an XML namespace declaration by its position.

An XMLNamespaces_t structure stores a list of pairs of namespaces and their prefixes. This method returns the URI of the nth element in that list (if it exists). Callers should use XMLAttributes_getLength() first to find out how many namespaces are stored in the list.

Parameters
nsthe XMLNamespaces_t structure.
indexan integer, position of the required URI.
Returns
the URI of an XML namespace declaration in this list (by position), or an empty string if the index is out of range.
See also
XMLNamespaces_getLength()
LIBLAX_EXTERN char * XMLNamespaces_getURIByPrefix ( const XMLNamespaces_t ns,
const char *  prefix 
)

Look up the URI of an XML namespace declaration by its prefix.

An XMLNamespaces_t object stores a list of pairs of namespaces and their prefixes. This method returns the namespace URI for a pair that has the given prefix.

Parameters
nsthe XMLNamespaces_t structure.
prefixa string, the prefix of the required URI.
Returns
the URI of an XML namespace declaration having the given prefix, or an empty string if no such prefix-and-URI pair exists in this XMLNamespaces_t object
Documentation note:
The native C++ implementation of this method defines a default argument value. In the documentation generated for different libSBML language bindings, you may or may not see corresponding arguments in the method declarations. For example, in Java and C#, a default argument is handled by declaring two separate methods, with one of them having the argument and the other one lacking the argument. However, the libSBML documentation will be identical for both methods. Consequently, if you are reading this and do not see an argument even though one is described, please look for descriptions of other variants of this method near where this one appears in the documentation.
See also
getURI()
LIBLAX_EXTERN int XMLNamespaces_hasNS ( const XMLNamespaces_t ns,
const char *  uri,
const char *  prefix 
)

Predicate returning 1 (true) or 0 (false) depending on whether an XML Namespace with the given URI is contained in this XMLNamespaces_t list.

Returns
1 (true) if an XML Namespace with the given uri/prefix pair is contained in this XMLNamespaces_t list, 0 (false) otherwise.
LIBLAX_EXTERN int XMLNamespaces_hasPrefix ( const XMLNamespaces_t ns,
const char *  prefix 
)

Predicate returning 1 (true) or 0 (false) depending on whether an XML Namespace the given prefix is contained in this XMLNamespaces_t list.

Returns
1 (true) if an XML Namespace with the given URI is contained in this XMLNamespaces_t list, 0 (false) otherwise.
LIBLAX_EXTERN int XMLNamespaces_hasURI ( const XMLNamespaces_t ns,
const char *  uri 
)

Predicate returning 1 (true) or 0 (false) depending on whether an XML Namespace with the given URI is contained in this XMLNamespaces_t list.

Returns
1 (true) if an XML Namespace with the given URI is contained in this XMLNamespaces_t list, 0 (false) otherwise.
LIBLAX_EXTERN int XMLNamespaces_isEmpty ( const XMLNamespaces_t ns)

Predicate returning 1 (true) or 0 (false) depending on whether this XMLNamespaces_t list is empty.

Returns
1 (true) if this XMLNamespaces_t list is empty, 0 (false) otherwise.
LIBLAX_EXTERN int XMLNamespaces_remove ( XMLNamespaces_t ns,
int  index 
)

Removes an XML Namespace stored in the given position of this list.

Parameters
nsXMLNamespaces_t structure.
indexan integer, position of the removed namespace.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are:
LIBLAX_EXTERN int XMLNamespaces_removeByPrefix ( XMLNamespaces_t ns,
const char *  prefix 
)

Removes an XML Namespace with the given prefix.

Parameters
nsXMLNamespaces_t structure.
prefixa string, prefix of the required namespace.
Returns
integer value indicating success/failure of the function. The value is drawn from the enumeration OperationReturnValues_t. The possible values returned by this function are: