InsertPIBefore (XmlNode function)
Insert a processing instruction before this node (XmlNode class)
[Requires Janus SOAP]
The InsertPIBefore callable function inserts a PI (Processing Instruction) node as the immediate sibling preceding the method XmlNode.
Syntax
[%outNod =] nod:InsertPIBefore( name, value)
Syntax terms
%outNod | 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 with the XmlDoc API".
- 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.
Examples
-
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.
- name violates the rules for an XML processing instruction target.
- value violates the rules for an XML processing instruction value.
See also
- 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 see the "InsertElementBefore: Examples".