Tests if the specified XML name (or element/attribute) belongs to one of the specified namespaces.

This function may be especially helpful when you want to know whether a particular XML name belongs to a certain namespace. To test it in ordinary way, you would need to write something like this:

qName.namespaceURI == "namespace URI"
That is, you will have to specify directly in the template the namespace URI, which may be a rather long string.

When you want to program a certain special processing of elements that belong to a particular namespace, and those elements are intermixed with elements from other namespaces, you may need to filter out the necessary elements possibly in many locations in the template. Specifying the namespace URI directly in all those locations may be very inconvenient.

This function allows you to avoid such a problem. Instead of comparing the namespace URIs directly in the template, you may first specify in the XML Type Configuration File (where the current XML data sources is described) a bindings between the namespace URI and a certain prefix. Then, you can use that prefix to refer to the URI.

Parameters:

qName

The QName object representing the XML name whose namespace is to be tested.

See also "About XML Names" below.

element
The element whose namespace is to be tested. (It is the same as testing element.dsmElement.qName)
attr
The attribute whose namespace is to be tested. (It is the same as testing attr.dsmAttr.qName)
<none>
If neither of the above parameters is specified, the generator context element will be assumed. That is, the call:
belongsToNS(prefixes)
is the same as the call:
belongsToNS(contextElement, prefixes)
prefixes
The string containing the semicolon (;) separated list of prefix names representing the namespaces.

Each prefix name should be declared in the XML Type Configuration File as part of the definition of the XML Type associated with the given template. The unknown prefix names will be ignored.

A special asterisk prefix name ("*") represents the global namespace. That is, calling

qName.belongsToNS("*")
is the same as comparing
qName.namespaceURI == ""
Returns:
true if the specified XML name/element/attribute belongs to one of the specified namespaces; false otherwise.

Example:

Let's suppose we want to check if the element element belongs either to XHTML namespace (associated with the URI: http://www.w3.org/1999/xhtml) or to the global namespace. Here's how it can be done.

First, in the XML Type Configuration File, we define the binding:


myxml.ns.1.prefix = xhtml
myxml.ns.1.uri = http://www.w3.org/1999/xhtml
where 'myxml' is the identifier of the XML Type associated with our template.

Now, to test the element's namespace, we may call:

element.belongsToNS("xhtml;*")

See Also:

getNamespaceURI(), testDefaultNS()

${include ../../../refs/xml_names.htm}