SelectionNamespace (XmlDoc property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 47: Line 47:
<li>All well-formed XmlDocs implicitly include this namespace declaration
<li>All well-formed XmlDocs implicitly include this namespace declaration
in scope at the top-level document element:
in scope at the top-level document element:
<pre>
<p class="code">xmlns:xml="http://www.w3.org/XML/1998/namespace"
    xmlns:xml="http://www.w3.org/XML/1998/namespace"
</p>
</pre>
The "xml" prefix is currently valid only for the special attributes
The "xml" prefix is currently valid only for the special attributes
<tt>xml:space</tt> and <tt>xml:lang</tt>.
<tt>xml:space</tt> and <tt>xml:lang</tt>.
Line 84: Line 83:
A subsequent invocation of SelectionNamespace returns the URI
A subsequent invocation of SelectionNamespace returns the URI
currently associated with the specified prefix.
currently associated with the specified prefix.
<pre>
<p class="code">Begin
    Begin
%doc is Object XmlDoc
    %doc is Object XmlDoc
%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:SelectionNamespace('SOAP')=  -
  'http://SCHEMAS.XMLSOAP.ORG/soap/'
      'http://SCHEMAS.XMLSOAP.ORG/soap/'
%n1 is Object XmlNode
    %n1 is Object XmlNode
%n1 = %doc:SelectSingleNode('top/a/SOAP:b')
    %n1 = %doc:SelectSingleNode('top/a/SOAP:b')
Call %n1:AddElement('c')
    Call %n1:AddElement('c')
Call %doc:Print
    Call %doc:Print
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:SelectionNamespace('SOAP')
End
    End
</p>
</pre>


The example result follows:
The example result follows:
<pre>
<p class="output"><top xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/">
    <top xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/">
  <a>
      <a>
      <SOAP:b>
          <SOAP:b>
        <c/>
            <c/>
      </SOAP:b>
          </SOAP:b>
  </a>
      </a>
</top>
    </top>
The URI of node SOAP:b is: http://SCHEMAS.XMLSOAP.ORG/soap/
    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/
    The URI for SOAP as an XPath prefix is: http://SCHEMAS.XMLSOAP.ORG/soap/
</p>
</pre>


===Request-Cancellation Errors===
===Request-Cancellation Errors===

Revision as of 05:44, 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