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"
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
element
element.dsmElement.qName
)
attr
attr.dsmAttr.qName
)
<none>
belongsToNS(prefixes)
belongsToNS(contextElement, prefixes)
prefixes
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("*")
qName.namespaceURI == ""
true
if the specified XML name/element/attribute belongs
to one of the specified namespaces; false
otherwise.
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
'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;*")
getNamespaceURI(), testDefaultNS()