PrefixURI (XmlDoc/XmlNode function): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 6: | Line 6: | ||
in the context of a node that is the head of an XPath result. | in the context of a node that is the head of an XPath result. | ||
The PrefixURI function is new as of version 6.9 of the ''Sirius Mods''. | The <var>PrefixURI</var> function is new as of version 6.9 of the ''Sirius Mods''. | ||
==Syntax== | ==Syntax== | ||
{{Template:XmlDoc/XmlNode:PrefixURI syntax}} | {{Template:XmlDoc/XmlNode:PrefixURI syntax}} | ||
Line 12: | Line 12: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%uri</th> | <tr><th>%uri</th> | ||
<td>A Unicode string variable for the returned URI. </td></tr> | <td>A <var>Unicode</var> string variable for the returned URI. </td></tr> | ||
<tr><th>nr</th> | <tr><th>nr</th> | ||
<td>An XmlDoc or XmlNode, used as the context node for the <i>XPath</i> expression. If an XmlDoc, the Root node is the context node. </td></tr> | <td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <i>XPath</i> expression. If an <var>XmlDoc</var>, the Root node is the context node. </td></tr> | ||
<tr><th>prefix</th> | <tr><th>prefix</th> | ||
<td>A Unicode string that is the prefix to "lookup" in the XmlDoc. If this is the null string, the ''%uri'' result is the default namespace at the node to process. Otherwise, the ''%uri'' result is the URI bound to <i>prefix</i> by a namespace declaration in scope at the node to process. In either case, the ''%uri'' result is null if there is no namespace associated with <i>prefix</i>. The prefix length must be at most 255 characters. </td></tr> | <td>A <var>Unicode</var> string that is the prefix to "lookup" in the <var>XmlDoc</var>. If this is the null string, the ''%uri'' result is the default namespace at the node to process. Otherwise, the ''%uri'' result is the URI bound to <i>prefix</i> by a namespace declaration in scope at the node to process. In either case, the ''%uri'' result is null if there is no namespace associated with <i>prefix</i>. The prefix length must be at most 255 characters. </td></tr> | ||
<tr><th>XPath</th> | <tr><th>XPath</th> | ||
<td>A Unicode string that is an XPath expression that results in a nodelist. The head of the nodelist is the node to process. An optional argument, its default is a period (.), that is, the node referenced by the method object (<i>nr</i>).</td></tr> | <td>A <var>Unicode</var> string that is an XPath expression that results in a nodelist. The head of the nodelist is the node to process. An optional argument, its default is a period (.), that is, the node referenced by the method object (<i>nr</i>).</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>As of ''Sirius Mods'' version 7.3, the method's arguments and result may include | <li>As of ''Sirius Mods'' version 7.3, the method's arguments and result may include | ||
only non-null EBCDIC characters that translate to Unicode. | only non-null EBCDIC characters that translate to <var>Unicode</var>. | ||
As of ''Sirius Mods'' version 7.6, these strings are Unicode or are converted to Unicode. | As of ''Sirius Mods'' version 7.6, these strings are <var>Unicode</var> or are converted to <var>Unicode</var>. | ||
For more information about the effects of this version 7.6 | For more information about the effects of this version 7.6 | ||
Line 35: | Line 35: | ||
In the following example, a node has a default URI defined as well as URIs | In the following example, a node has a default URI defined as well as URIs | ||
for two prefixes. | for two prefixes. | ||
PrefixURI calls return the three URIs: | <var>PrefixURI</var> calls return the three URIs: | ||
<p class="code">Begin | <p class="code">Begin | ||
%d Object XmlDoc Auto New | %d <var>Object</var> <var>XmlDoc</var> Auto New | ||
%n Object XmlNode | %n <var>Object</var> <var>XmlNode</var> | ||
%n = %d:AddElement('x', , 'urn:default') | %n = %d:AddElement('x', , 'urn:default') | ||
%n:AddNamespace('foo', 'urn:foo') | %n:AddNamespace('foo', 'urn:foo') | ||
%n:AddNamespace('bar', 'urn:bar') | %n:AddNamespace('bar', 'urn:bar') | ||
%n:Print | %n:Print | ||
Print 'Default namespace URI =' And %n:PrefixURI('') | Print 'Default namespace URI =' And %n:<var>PrefixURI</var>('') | ||
Print 'URI bound to prefix "foo" =' And %n:PrefixURI('foo') | Print 'URI bound to prefix "foo" =' And %n:<var>PrefixURI</var>('foo') | ||
Print 'URI bound to prefix "bar" =' And %n:PrefixURI('bar') | Print 'URI bound to prefix "bar" =' And %n:<var>PrefixURI</var>('bar') | ||
End | End | ||
</p> | </p> | ||
Line 57: | Line 57: | ||
===Request-Cancellation Errors=== | ===Request-Cancellation Errors=== | ||
<ul> | <ul> | ||
<li>XmlDoc Namespace property not <tt>On</tt>. | <li><var>XmlDoc</var> Namespace property not <tt>On</tt>. | ||
<li><i>XPath</i> is invalid. | <li><i>XPath</i> is invalid. | ||
<li>Result of (<i>XPath</i>) is empty. | <li>Result of (<i>XPath</i>) is empty. | ||
Line 76: | Line 76: | ||
The URI method ([[??]] refid=uri.) returns the URI bound to a node's name, | The URI method ([[??]] refid=uri.) returns the URI bound to a node's name, | ||
if any. | if any. | ||
<li>These methods add namespace URIs to XmlDoc nodes: | <li>These methods add namespace URIs to <var>XmlDoc</var> nodes: | ||
<ul> | <ul> | ||
<li>[[AddElement (XmlDoc/XmlNode function)|AddElement]] | <li>[[AddElement (XmlDoc/XmlNode function)|AddElement]] |
Revision as of 17:46, 25 January 2011
URI of specified prefix in context of selected node (XmlDoc and XmlNode classes)
This function 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.
The PrefixURI function is new as of version 6.9 of the Sirius Mods.
Syntax
%unicode = nr:PrefixURI( prefix, [xpath]) Throws XPathError
Syntax terms
%uri | 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 "lookup" in the XmlDoc. If this is the null string, the %uri result is the default namespace at the node to process. Otherwise, the %uri result is the URI bound to prefix by a namespace declaration in scope at the node to process. In either case, the %uri 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 to process. An optional argument, 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. For an example of a specific effect that involves the Value method, see item ?? refid=univalx..
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
- XmlDoc Namespace property not On.
- XPath is invalid.
- Result of (XPath) is empty.
- Insufficient free space exists in CCATEMP.
See also
- For more information about using XPath expressions, see XPath.
- For more information about namespace declarations, see ?? refid=namsp..
- For more information about URIs, see ?? refid=nsuri..
- The DefaultURI method returns the default URI, if a node has a default namespace declaration; otherwise it returns a null string. The URI method (?? refid=uri.) returns the URI bound to a node's name, if any.
- These methods add namespace URIs to XmlDoc nodes: