PrefixURI (XmlDoc/XmlNode function)

From m204wiki
Jump to navigation Jump to search

URI of specified prefix in context of selected node (XmlDoc and XmlNode classes)

PrefixURI can get the Uniform Resource Identifier (URI) associated with a prefix, or it can get the default URI (if a node has a default namespace declaration), in the context of a node that is the head of an XPath result.


%unicode = nr:PrefixURI( prefix, [xpath]) Throws XPathError

Syntax terms

%unicode A Unicode string variable for the returned URI.
nr An XmlDoc or XmlNode, used as the context node for the xpath expression. If an XmlDoc, the Root node is the context node.
prefix A Unicode string that is the prefix to "look up" in the XmlDoc. If this is the null string, the %unicode result is the default namespace at the node to process. Otherwise, the %unicode result is the URI bound to prefix by a namespace declaration in scope at the node to process. In either case, the %unicode result is null if there is no namespace associated with prefix. The prefix length must be at most 255 characters.
xpath A Unicode string that is an XPath expression that results in a nodelist. The head of the nodelist is the node used as the XML document context for the URI lookup. Any other nodes in the nodelist are ignored.

This is an optional argument, and its default is a period (.), that is, the node referenced by the method object (nr).

Usage notes

  • As of Sirius Mods Version 7.3, the method's arguments and result may include only non-null EBCDIC characters that translate to Unicode. As of Sirius Mods Version 7.6, these strings are Unicode or are converted to Unicode.

    For more information about the effects of this Version 7.6 change, see "Strings and Unicode with the XmlDoc API". For an example of a specific effect that involves the Value method, see this example.


In the following example, a node has a default URI defined as well as URIs for two prefixes. PrefixURI calls return the three URIs:

begin %d object xmlDoc auto new %n object xmlNode %n = %d:addElement('x', , 'urn:default') %n:addNamespace('foo', 'urn:foo') %n:addNamespace('bar', 'urn:bar') %n:print print 'Default namespace URI =' and %n:prefixURI('') print 'URI bound to prefix "foo" =' and %n:prefixURI('foo') print 'URI bound to prefix "bar" =' and %n:prefixURI('bar') end

The following lines are printed:

<x xmlns="urn:default" xmlns:foo="urn:foo" xmlns:bar="urn:bar"/> Default namespace URI = urn:default URI bound to prefix "foo" = urn:foo URI bound to prefix "bar" = urn:bar

Request-cancellation errors

This list is not exhaustive: it does not include all the errors that are request cancelling.

  • XmlDoc Namespace property value not On.
  • The xpath expression is invalid.
  • Result of xpath is empty.
  • Insufficient free space exists in CCATEMP.

See also