all Python 3xml.etree.ElementTreefunction
xml.etree.ElementTree.ProcessingInstruction()
comments and instructions
A factory for a processing instruction <?target text?>, such as xml-stylesheet. The short name ET.PI is the same object.
Syntax
pi = ET.ProcessingInstruction(target, text=None)
As with Comment, the element's tag is the function itself, not a string; test elem.tag is ET.PI when walking a tree. The <?xml …?> declaration is not a processing instruction, so do not build it with PI; xml_declaration in write()/tostring() controls it. Parsing drops instructions by default; keep them via TreeBuilder(insert_pis=True).
Examples
import xml.etree.ElementTree as ET
pi = ET.PI('xml-stylesheet', 'href="s.css"')
print(ET.tostring(pi, encoding='unicode')) # → <?xml-stylesheet href="s.css"?>
print(ET.PI is ET.ProcessingInstruction, pi.tag is ET.PI) # → True True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy