InsertPIBefore (XmlNode function): Difference between revisions
Jump to navigation
Jump to search
m (1 revision) |
m (→Example) |
||
Line 41: | Line 41: | ||
a PI node is inserted before node "top": | a PI node is inserted before node "top": | ||
<p class="code">Begin | <p class="code">Begin | ||
%doc is | %doc is Object XmlDoc | ||
%doc = New | %doc = New | ||
Call %doc:LoadXml('<top><a><b>05</b></a></top>') | Call %doc:LoadXml('<top><a><b>05</b></a></top>') | ||
%n1 is | %n1 is Object XmlNode | ||
%n1 = %doc:SelectSingleNode('top') | %n1 = %doc:SelectSingleNode('top') | ||
Call %n1: | Call %n1:InsertPIBefore('xml-stylesheet', - | ||
'type="text/xsl" href="transfor.xsl"') | 'type="text/xsl" href="transfor.xsl"') | ||
Call %doc:Print | Call %doc:Print | ||
End | End | ||
Line 56: | Line 55: | ||
<p class="code"><?xml-stylesheet type="text/xsl" href="transfor.xsl"?> | <p class="code"><?xml-stylesheet type="text/xsl" href="transfor.xsl"?> | ||
<top> | <top> | ||
<a> | <a> | ||
<b>05</b> | |||
</a> | |||
</top> | </top> | ||
</p> | </p> |
Revision as of 17:52, 7 February 2011
Insert a processing instruction before this node (XmlNode class)
[Requires Janus SOAP]
This callable function inserts a PI (Processing Instruction) node as the immediate
sibling preceding the method XmlNode.
Syntax
[%outNod =] nod:InsertPIBefore( name, value)
Syntax terms
%nod | If specified, an XmlNode that is set to point to the PI node that is inserted. |
---|---|
nod | XmlNode pointing to the (non-Root) node before which the PI node is inserted. |
name | A Unicode string that is the target of the inserted PI node; this can be thought of as the "name" of the PI. It must conform to the XML syntax rules for a PI target; the maximum length of the name is 127 characters (100 characters prior to version 7.7 of Janus SOAP). |
value | A Unicode string that is the value of the inserted PI node; stored exactly as is, that is, without whitespace normalization. |
Usage notes
- As of Sirius Mods version 7.3, the InsertPIBefore 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.
- Since the return value of InsertPIBefore is frequently not needed, you may want to Call it instead of saving its return value.
- There is a very small "one-time" processing cost if certain XPath operations are performed after using this method, because Insert-Before methods are guaranteed to add a node out of document order. In general, processing an XmlDoc is likely to be more efficient if you add nodes in document order (that is, top-to-bottom, left-to-right).
- To modify the value stored in a PI node, change the Value property of an XmlNode that points to the PI node.
Example
In the following example, a PI node is inserted before node "top":
Begin %doc is Object XmlDoc %doc = New Call %doc:LoadXml('<top><a>05</a></top>') %n1 is Object XmlNode %n1 = %doc:SelectSingleNode('top') Call %n1:InsertPIBefore('xml-stylesheet', - 'type="text/xsl" href="transfor.xsl"') Call %doc:Print End
The example results follow:
<?xml-stylesheet type="text/xsl" href="transfor.xsl"?> <top> <a> 05 </a> </top>
Request-Cancellation Errors
- Nod is the Root node.
- Argument name violates the rules for an XML processing instruction target.
- Argument value violates the rules for an XML processing instruction value.
See also
- AddPI (?? reftxt=AddPI refid=addpi.) also adds a PI node. InsertPIBefore adds a PI as the immediately preceding sibling of the node pointed to by the method object. AddPI adds a PI as the last child of the node pointed to by the method object.
- For hints about inserting a node after a sibling node, see the "Example" section in InsertElementBefore.