SelectionNamespace (XmlDoc property): Difference between revisions
m (1 revision) |
m (1 revision) |
(No difference)
|
Revision as of 16:12, 7 February 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
- 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:
- Use any other "xml" prefixed element or attribute names
- Add a namespace declaration (??AddNamespace) for the "xml" prefix for a URI other than "http://www.w3.org/xml/1998/namespace"
- Add a namespace declaration for "http://www.w3.org/xml/1998/namespace" that has any other prefix besides "xml"
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
- For more information about namespaces, see ?? refid=namsp., including its subsections.
- These methods are also useful for working with namespaces:
- These methods are useful for working with prefixes: