InsertPIBefore (XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
mNo edit summary
Line 1: Line 1:
<span style="font-size:120%; color:black"><b>Insert Processing Instruction before XmlNode</b></span>
{{Template:XmlNode:InsertPIBefore subtitle}}
[[Category:XmlNode methods|InsertPIBefore function]]
[[Category:XmlNode methods|InsertPIBefore function]]
[[Category:XmlDoc API methods]]
[[Category:XmlDoc API methods]]
Line 11: Line 11:
This callable function inserts a PI (Processing Instruction) node as the immediate
This callable function inserts a PI (Processing Instruction) node as the immediate
sibling preceding the method XmlNode.
sibling preceding the method XmlNode.
===Syntax===
==Syntax==
  [%nod =] nod:InsertPIBefore(name, value)
{{Template:XmlNode:InsertPIBefore syntax}}
 
===Syntax terms===
====Syntax Terms====
<dl>
<dl>
<dt>%nod
<dt>%nod
Line 22: Line 21:
<dt>name
<dt>name
<dd>A Unicode string that is the target of the inserted PI node;
<dd>A Unicode string that is the target of the inserted PI node;
this can be thought of as the &ldquo;name&rdquo; of the PI.
this can be thought of as the "name" of the PI.
It must conform to the XML syntax rules for a PI target; the
It must conform to the XML syntax rules for a PI target; the
maximum length of the name is 127 characters
maximum length of the name is 127 characters
Line 32: Line 31:
</dl>
</dl>


===Usage Notes===
==Usage notes==
<ul>
<ul>
<li>As of ''Sirius Mods'' version 7.3, the InsertPIBefore method arguments may
<li>As of ''Sirius Mods'' version 7.3, the InsertPIBefore method arguments may
Line 42: Line 41:
<li>Since the return value of InsertPIBefore is frequently not needed,
<li>Since the return value of InsertPIBefore is frequently not needed,
you may want to Call it instead of saving its return value.
you may want to Call it instead of saving its return value.
<li>There is a very small &ldquo;one-time&rdquo; processing cost
<li>There is a very small "one-time" processing cost
if certain XPath operations are performed after using this method, because
if certain XPath operations are performed after using this method, because
Insert-Before methods are guaranteed to add a node out of document order.
Insert-Before methods are guaranteed to add a node out of document order.
Line 54: Line 53:


In the following example,
In the following example,
a PI node is inserted before node &ldquo;top&rdquo;:
a PI node is inserted before node "top":
<pre>
<pre>
     Begin
     Begin
Line 98: Line 97:
method object.
method object.
<li>For hints about inserting a node ''after'' a sibling node, see
<li>For hints about inserting a node ''after'' a sibling node, see
the &ldquo;Example&rdquo; section in [[InsertElementBefore (XmlNode function)|InsertElementBefore]].
the "Example" section in [[InsertElementBefore (XmlNode function)|InsertElementBefore]].
</ul>
</ul>

Revision as of 16:58, 22 January 2011

Insert a processing instruction before this node (XmlNode class)

[Requires Janus SOAP]

InsertPIBefore is a member of the XmlNode class.

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><b>05</b></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>
          <b>05</b>
       </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.