Commits

Alain Poirier committed e5352d5

Processing Instruction added

Comments (0)

Files changed (1)

nagare/namespaces/xml.py

 
     Do nothing
     """
-    pass
+    self.append(element)
 
 
 @peak.rules.when(add_child, (_Tag, dict))
 def add_attribute(self, name, value):
     self.set(name, value)
 
+@peak.rules.when(add_attribute, (ET._ProcessingInstruction, basestring, basestring))
+def add_attribute(self, name, value):
+    self.text += (' %s="%s"' % (name, value))
+
 # ---------------------------------------------------------------------------
 
 class TagProp(object):
         """
         return ET.Comment(text)
 
+    def processing_instruction(self, target, text=None, **kw):
+        """Create a processing instruction element
+
+        In:
+          - ``target`` -- the PI target
+          - ``text`` -- the PI text
+          - ``kw`` -- pseudo attributes
+
+        Return:
+          - the new processing instruction element
+        """
+        pi = ET.ProcessingInstruction(target, text)
+
+        for name, value in kw.iteritems():
+            if name.endswith('_'):
+                name = name[:-1]
+
+            add_attribute(pi, name, value)
+
+        return pi
+
     def parse_xml(self, source, fragment=False, no_leading_text=False, **kw):
         """Parse a XML file