InsertPIBefore (XmlNode function)
Insert a processing instruction before this node (XmlNode class)
[Requires Janus SOAP]
[%outNod =] nod:InsertPIBefore( name, value)
|%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 300 characters (127 characters prior to version 7.9, and 100 characters prior to version 7.7).|
|value||A Unicode string that is the value of the inserted PI node; stored exactly as is, that is, without whitespace normalization.|
- 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 expression 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.
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>
This list is not exhaustive: it does not include all the errors that are request cancelling.
- The nod object is the Root node.
- The name argument violates the rules for an XML processing instruction target.
- The value argument violates the rules for an XML processing instruction value.
- 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 InsertElementBefore examples.