SelectionNamespace (XmlDoc property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 9: Line 9:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>doc</th>
<tr><th>doc</th>
<td>An XmlDoc expresssion. </td></tr>
<td>An <var>XmlDoc</var> expresssion. </td></tr>
<tr><th>prefix</th>
<tr><th>prefix</th>
<td>The prefix to be used in XPath expressions. This is a Unicode string argument; prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
<td>The prefix to be used in XPath expressions. This is a <var>Unicode</var> string argument; prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
<tr><th>newURI</th>
<tr><th>newURI</th>
<td>The namespace absolute URI to associate with <i>prefix</i>, or the null string, if the prefix is not associated with the URI of a namespace. This is a Unicode string argument; prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
<td>The namespace absolute URI to associate with <i>prefix</i>, or the null string, if the prefix is not associated with the URI of a namespace. This is a <var>Unicode</var> string argument; prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string. </td></tr>
<tr><th>%currURI</th>
<tr><th>%currURI</th>
<td>A Unicode string %variable, set to the namespace URI associated with <i>prefix</i>. Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string.</td></tr>
<td>A <var>Unicode</var> string %variable, set to the namespace URI associated with <i>prefix</i>. Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string.</td></tr>
</table>
</table>


Line 21: Line 21:
<ul>
<ul>
<li>When you use a name in an XPath expression to select an
<li>When you use a name in an XPath expression to select an
element or attribute in an XmlDoc, you locate only elements or attributes whose
element or attribute in an <var>XmlDoc</var>, you locate only elements or attributes whose
LocalName and URI match the XPath name.
LocalName and URI match the XPath name.
You use SelectionNamespace to specify a prefix you can use for the name in
You use <var>SelectionNamespace</var> to specify a prefix you can use for the name in
your XPath expression to identify the URI of the element or attribute you
your XPath expression to identify the URI of the element or attribute you
are trying to locate.
are trying to locate.
Line 31: Line 31:
However, if an element or attribute name you want to match
However, if an element or attribute name you want to match
has a prefix, you cannot select the element or attribute by
has a prefix, you cannot select the element or attribute by
prefix and name ''until the prefix is defined via the SelectionNamespace
prefix and name ''until the prefix is defined via the <var>SelectionNamespace</var>
method''.
method''.
<li>An element (but not an attribute) name with no prefix may still
<li>An element (but not an attribute) name with no prefix may still
Line 38: Line 38:
(see [[??]] refid=namsyn.).
(see [[??]] refid=namsyn.).
To locate this element by name with an XPath expression, you must
To locate this element by name with an XPath expression, you must
use SelectionNamespace to associate a prefix with the URI of the element name,
use <var>SelectionNamespace</var> to associate a prefix with the URI of the element name,
and use the prefix and local name of the element in the XPath expression.
and use the prefix and local name of the element in the XPath expression.
<li>All well-formed XmlDocs implicitly include this namespace declaration
<li>All well-formed <var>XmlDoc</var>s implicitly include this namespace declaration
in scope at the top-level document element:
in scope at the top-level document element:
<p class="code">xmlns:xml="http://www.w3.org/XML/1998/namespace"
<p class="code">xmlns:xml="http://www.w3.org/XML/1998/namespace"
Line 57: Line 57:


The URI "http://www.w3.org/xml/1998/namespace" is
The URI "http://www.w3.org/xml/1998/namespace" is
the value of SelectionNamespace if "xml" is the method argument.
the value of <var>SelectionNamespace</var> if "xml" is the method argument.
<li>Prior to version 7.0 of the ''Sirius Mods'', if the URI associated with a prefix
<li>Prior to version 7.0 of the ''Sirius Mods'', if the URI associated with a prefix
is the null string, that prefix cannot be used in an XPath expression.
is the null string, that prefix cannot be used in an XPath expression.
Line 65: Line 65:
<li>The initial URI associated with any prefix is the null string.
<li>The initial URI associated with any prefix is the null string.
Therefore, prior to version 7.0 of the ''Sirius Mods'',
Therefore, prior to version 7.0 of the ''Sirius Mods'',
you had to set the SelectionNamespace property for ''any'' prefix to a
you had to set the <var>SelectionNamespace</var> property for ''any'' prefix to a
non-null string before it could be used in an XPath expression.
non-null string before it could be used in an XPath expression.
For version 7.0 and later, you have to set the SelectionNamespace property for
For version 7.0 and later, you have to set the <var>SelectionNamespace</var> property for
any prefix ''that is associated with a namespace URI''.
any prefix ''that is associated with a namespace URI''.
</ul>
</ul>
Line 73: Line 73:
===Example===
===Example===


In the following example, the SelectionNamespace setting associates
In the following example, the <var>SelectionNamespace</var> setting associates
the prefix "SOAP" with its URI, enabling the use of that prefix
the prefix "SOAP" with its URI, enabling the use of that prefix
later in the XPath expression in the SelectSingleNode method invocation.
later in the XPath expression in the SelectSingleNode method invocation.
A subsequent invocation of SelectionNamespace returns the URI
A subsequent invocation of <var>SelectionNamespace</var> returns the URI
currently associated with the specified prefix.
currently associated with the specified prefix.
<p class="code">Begin
<p class="code">Begin
%doc is Object XmlDoc
%doc is <var>Object</var> <var>XmlDoc</var>
%doc = New
%doc = New
%doc:LoadXml('<top  -
%doc:LoadXml('<top  -
   xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/">  -
   xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/">  -
   <a><SOAP:b></SOAP:b></a></top>')
   <a><SOAP:b></SOAP:b></a></top>')
%doc:SelectionNamespace('SOAP')=  -
%doc:<var>SelectionNamespace</var>('SOAP')=  -
   'http://SCHEMAS.XMLSOAP.ORG/soap/'
   'http://SCHEMAS.XMLSOAP.ORG/soap/'
%n1 is Object XmlNode
%n1 is <var>Object</var> <var>XmlNode</var>
%n1 = %doc:SelectSingleNode('top/a/SOAP:b')
%n1 = %doc:SelectSingleNode('top/a/SOAP:b')
Call %n1:AddElement('c')
Call %n1:AddElement('c')
Line 92: Line 92:
Print 'The URI of node SOAP:b is: ' %n1:URI
Print 'The URI of node SOAP:b is: ' %n1:URI
Print 'The URI for SOAP as an XPath prefix is:' And -
Print 'The URI for SOAP as an XPath prefix is:' And -
   %doc:SelectionNamespace('SOAP')
   %doc:<var>SelectionNamespace</var>('SOAP')
End
End
</p>
</p>

Revision as of 17:46, 25 January 2011

Bind prefix to URI (or null) for XPath (XmlDoc class)


This property indicates the value of the namespace URI associated with a prefix, when the prefix is used in an XPath expression.

Syntax

%currentUnicode = doc:SelectionNamespace( prefix) doc:SelectionNamespace( prefix) = newUnicode

Syntax terms

doc An XmlDoc expresssion.
prefix The prefix to be used in XPath expressions. This is a Unicode string argument; prior to Sirius Mods version 7.6, this is an EBCDIC string.
newURI The namespace absolute URI to associate with prefix, or the null string, if the prefix is not associated with the URI of a namespace. This is a Unicode string argument; prior to Sirius Mods version 7.6, this is an EBCDIC string.
%currURI A Unicode string %variable, set to the namespace URI associated with prefix. Prior to Sirius Mods version 7.6, this is an EBCDIC string.

Usage notes

  • When you use a name in an XPath expression to select an element or attribute in an XmlDoc, you locate only elements or attributes whose LocalName and URI match the XPath name. You use SelectionNamespace to specify a prefix you can use for the name in your XPath expression to identify the URI of the element or attribute you are trying to locate.
    note
    Your XPath expression need not use a prefix if the element or attribute name to be matched does not have a URI. However, if an element or attribute name you want to match has a prefix, you cannot select the element or attribute by prefix and name until the prefix is defined via the SelectionNamespace method.
  • An element (but not an attribute) name with no prefix may still have a URI. Such an element may have an in-scope "default namespace declaration" (see ?? refid=namsyn.). To locate this element by name with an XPath expression, you must use SelectionNamespace to associate a prefix with the URI of the element name, and use the prefix and local name of the element in the XPath expression.
  • All well-formed XmlDocs implicitly include this namespace declaration in scope at the top-level document element:

    xmlns:xml="http://www.w3.org/XML/1998/namespace"

    The "xml" prefix is currently valid only for the special attributes xml:space and xml:lang. You are not allowed to:

    The URI "http://www.w3.org/xml/1998/namespace" is the value of SelectionNamespace if "xml" is the method argument.

  • Prior to version 7.0 of the Sirius Mods, if the URI associated with a prefix is the null string, that prefix cannot be used in an XPath expression. The version 7.0 (and later) interpretation of a null-string setting (null string means "no namespace") is a Sirius extension to the XPath Recommendation.
  • The initial URI associated with any prefix is the null string. Therefore, prior to version 7.0 of the Sirius Mods, you had to set the SelectionNamespace property for any prefix to a non-null string before it could be used in an XPath expression. For version 7.0 and later, you have to set the SelectionNamespace property for any prefix that is associated with a namespace URI.

Example

In the following example, the SelectionNamespace setting associates the prefix "SOAP" with its URI, enabling the use of that prefix later in the XPath expression in the SelectSingleNode method invocation. A subsequent invocation of SelectionNamespace returns the URI currently associated with the specified prefix.

Begin %doc is Object XmlDoc %doc = New %doc:LoadXml('<top - xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/"> - <a><SOAP:b></SOAP:b></a></top>') %doc:SelectionNamespace('SOAP')= - 'http://SCHEMAS.XMLSOAP.ORG/soap/' %n1 is Object XmlNode %n1 = %doc:SelectSingleNode('top/a/SOAP:b') Call %n1:AddElement('c') Call %doc:Print Print 'The URI of node SOAP:b is: ' %n1:URI Print 'The URI for SOAP as an XPath prefix is:' And - %doc:SelectionNamespace('SOAP') End

The example result follows:

<top xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/"> <a> <SOAP:b> <c/> </SOAP:b> </a> </top> The URI of node SOAP:b is: http://SCHEMAS.XMLSOAP.ORG/soap/ The URI for SOAP as an XPath prefix is: http://SCHEMAS.XMLSOAP.ORG/soap/

Request-Cancellation Errors

  • Prefix is not a valid name prefix.
  • Argument newURI is not a valid absolute Uniform Resource Identifier.


See also