PI is an abbreviation for Processing Instruction, an element of an XML document that tells the parser reading the document to "do some processing".

The most common PI is the:

<?xml version="1.0"?>
instruction which appears at the top of every (version 1) XML file. This tells the parser that the file is infact an XML file, that it is XML version 1, and that it should parse it as such.

You can place other PI's in your XML document of course. These can be anything you want, for example you could have something like:

<?code
return("This is some rather uninteresting code embedded into a PI inside an XML file");
?>
Then when your XML parser comes across the PI called "code", it can invoke the correct scripting engine with the contents of the PI.

Cool hey.

Of course you could just have a tag like:

<code>
<![CDATA[
return("This is some rather uninteresting code embedded into a PI inside an XML file");
]]>
</code>
and invoke the scripting engine when the parser finds this tag, however then you need to add a CDATA section as the code is actually part of the XML file.

Processing Instructions are a neat little addition to the XML specification, allowing you to do stuff that isn't anything to do with XML within an XML environment. Thank you W3C.

Log in or register to write something here or to contact authors.