Next / Previous / Contents / Shipman's homepage

7.6. The ProcessingInstruction() constructor

To add an XML processing instruction to your document, use this constructor. It returns a new ProcessingInstruction instance; to place this into a tree, pass that instance to the parent element's .append() method.

etree.ProcessingInstruction(target, text=None):

A string containing the target portion of the processing instruction.


An optional string containing the rest of the processing instruction. The default value is empty.

Here's an example:

pi = etree.ProcessingInstruction('decor', 'danish,modern,ducksOnWall')

When converted back to XML, this processing instruction would look like this:

<?decor danish,modern,ducksOnWall?>