AddNamespace (XmlNode subroutine): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 8: | Line 8: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>nod</th> | <tr><th>nod</th> | ||
<td>An XmlNode that points to the Element node where the namespace declaration is added. </td></tr> | <td>An <var>XmlNode</var> that points to the Element node where the namespace declaration is added. </td></tr> | ||
<tr><th>prefix</th> | <tr><th>prefix</th> | ||
<td>The prefix that is being declared. It must conform to the XML syntax rules for a namespace prefix; the maximum length of the prefix is 127 characters (100 characters prior to version 7.7 of [[Janus SOAP]]). </td></tr> | <td>The prefix that is being declared. It must conform to the XML syntax rules for a namespace prefix; the maximum length of the prefix is 127 characters (100 characters prior to version 7.7 of [[Janus SOAP]]). </td></tr> | ||
Line 17: | Line 17: | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>If a URI argument is specified, the XmlDoc's [[Namespace (XmlDoc property)|Namespace]] property must be <tt>On</tt>. | <li>If a URI argument is specified, the <var>XmlDoc</var>'s [[Namespace (XmlDoc property)|Namespace]] property must be <tt>On</tt>. | ||
<li>As of ''Sirius Mods'' version 7.3, the AddNamespace method arguments may | <li>As of ''Sirius Mods'' version 7.3, the <var>AddNamespace</var> method arguments may | ||
include only non-null EBCDIC characters that translate to Unicode. | include only non-null EBCDIC characters that translate to <var>Unicode</var>. | ||
As of ''Sirius Mods'' version 7.6, these argument strings are Unicode or are | As of ''Sirius Mods'' version 7.6, these argument strings are <var>Unicode</var> or are | ||
converted to Unicode. | 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 | ||
change, see [[XmlDoc API#Strings and Unicode with the XmlDoc API|Strings and Unicode with the XmlDoc API]]. | change, see [[XmlDoc API#Strings and Unicode with the XmlDoc API|Strings and Unicode with the XmlDoc API]]. | ||
Line 32: | Line 32: | ||
may not be added to an Element that has the same prefix (including no | may not be added to an Element that has the same prefix (including no | ||
prefix, in the case of the default namespace declaration) if the | prefix, in the case of the default namespace declaration) if the | ||
Element's URI differs from the AddNamespace URI. | Element's URI differs from the <var>AddNamespace</var> URI. | ||
<li>A namespace declaration | <li>A namespace declaration | ||
may not be added to an Element that has the same prefix | may not be added to an Element that has the same prefix | ||
Line 41: | Line 41: | ||
does not apply to the top-level Element of a subtree. | does not apply to the top-level Element of a subtree. | ||
</ul> | </ul> | ||
<li>All well-formed | <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 60: | Line 60: | ||
===Example=== | ===Example=== | ||
In the following example, the AddNamespace method adds a namespace to a node | In the following example, the <var>AddNamespace</var> method adds a namespace to a node | ||
that has an existing namespace. Subsequent elements are added to that node | that has an existing namespace. Subsequent elements are added to that node | ||
using each of the eligible namespace prefixes. | using each of the eligible namespace prefixes. | ||
<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>') | ||
%n1 is Object XmlNode | %n1 is <var>Object</var> <var>XmlNode</var> | ||
%n2 is Object XmlNode | %n2 is <var>Object</var> <var>XmlNode</var> | ||
%n3 is Object XmlNode | %n3 is <var>Object</var> <var>XmlNode</var> | ||
%n1 = %doc:SelectSingleNode('top/*/*') | %n1 = %doc:SelectSingleNode('top/*/*') | ||
Call %n1:AddNamespace('sirius', 'http://sirius-software.com') | Call %n1:<var>AddNamespace</var>('sirius', 'http://sirius-software.com') | ||
Print 'The URI of node SOAP:b is: ' %n1:URI | Print 'The URI of node SOAP:b is: ' %n1:URI | ||
%n2 = %n1:AddElement('sirius:c') | %n2 = %n1:AddElement('sirius:c') | ||
Line 109: | Line 109: | ||
<i>URI</i> is already present (not merely in scope) at the Element pointed to by | <i>URI</i> is already present (not merely in scope) at the Element pointed to by | ||
<i>nod</i>. | <i>nod</i>. | ||
<li>The XmlDoc's Namespace property is not On. | <li>The <var>XmlDoc</var>'s Namespace property is not On. | ||
</ul> | </ul> | ||
Revision as of 17:46, 25 January 2011
Add namespace declaration to Element node (XmlNode class)
[Requires Janus SOAP]
This subroutine adds a namespace declaration to an Element node.
Syntax
nod:AddNamespace( prefix, uri)
Syntax terms
nod | An XmlNode that points to the Element node where the namespace declaration is added. |
---|---|
prefix | The prefix that is being declared. It must conform to the XML syntax rules for a namespace prefix; the maximum length of the prefix is 127 characters (100 characters prior to version 7.7 of Janus SOAP). |
URI | An absolute Uniform Resource Identifier, identifying the namespace the prefix is declared within. |
Usage notes
- If a URI argument is specified, the XmlDoc's Namespace property must be On.
- As of Sirius Mods version 7.3, the AddNamespace method arguments may include only non-null EBCDIC characters that translate to Unicode. As of Sirius Mods version 7.6, these argument 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.
- Namespace declarations are serialized in the order in which they are added.
- Adding the same declaration multiple times on an element is allowed.
- To ensure that URIs of already added nodes are preserved:
- A namespace declaration may not be added to an Element that has the same prefix (including no prefix, in the case of the default namespace declaration) if the Element's URI differs from the AddNamespace URI.
- A namespace declaration may not be added to an Element that has the same prefix if the Element's URI differs from any of the Element's attributes.
- A namespace declaration may not be added to an Element that has Element children. As of Sirius Mods version 7.7, this restriction does not apply to the top-level Element of a subtree.
- 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 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"
Example
In the following example, the AddNamespace method adds a namespace to a node that has an existing namespace. Subsequent elements are added to that node using each of the eligible namespace prefixes.
Begin %doc is Object XmlDoc %doc = New %doc:LoadXml('<top - xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/"> - <a><SOAP:b></SOAP:b></a></top>') %n1 is Object XmlNode %n2 is Object XmlNode %n3 is Object XmlNode %n1 = %doc:SelectSingleNode('top/*/*') Call %n1:AddNamespace('sirius', 'http://sirius-software.com') Print 'The URI of node SOAP:b is: ' %n1:URI %n2 = %n1:AddElement('sirius:c') %n3 = %n1:AddElement('SOAP:c') Call %doc:Print Print 'The URI of node sirius:c is: ' %n2:URI Print 'The URI of node SOAP:c is: ' %n3:URI End
The example result follows:
The URI of node SOAP:b is: http://SCHEMAS.XMLSOAP.ORG/soap/ <top xmlns:SOAP="http://SCHEMAS.XMLSOAP.ORG/soap/"> <a> <SOAP:b xmlns:sirius="http://sirius-software.com"> <sirius:c/> <SOAP:c/> </SOAP:b> </a> </top> The URI of node sirius:c is: http://sirius-software.com The URI of node SOAP:c is: http://SCHEMAS.XMLSOAP.ORG/soap/
Request-Cancellation Errors
- Nod does not point to an Element node.
- Element pointed to by nod contains one or more child Element nodes.
- Prefix is an invalid prefix.
- URI is an invalid URI.
- Prefix is the same as the prefix of the Element that nod points to, but URI is different from the namespace URI of the Element.
- A declaration for the same prefix with a different URI is already present (not merely in scope) at the Element pointed to by nod.
- The XmlDoc's Namespace property is not On.
See also
- For more information about namespace declarations, see Names and namespaces.
- For more information about URIs, see Uniform Resource Identifier syntax.
- For more information about namespaces and adding nodes, see XmlDoc API#Namespaces with Add* and Insert* methods.
- These methods are also useful for working with namespaces: