Commits

Anonymous committed cb13868

manipulating

  • Participants
  • Parent commits b72d923
  • Branches manipulating

Comments (0)

Files changed (1)

File pyquery/__init__.py

 You can use the PyQuery class to load an xml document from a string, from a
 file or from an url.
 
-    >>> from pyquery import PyQuery
     >>> d = PyQuery(html="<html></html>")
     >>> d = PyQuery(url='http://w3c.org/')
     >>> d = PyQuery(filename="test.html")
     >>> p.attr("style")
     'font-size: 17px'
 
+You can also add content to the end of a tag
+
+    >>> p.append("hey there !")
+    [<p#hello.hello>]
+    >>> p.text()
+    'you know Python rocks'
+    >>> p.html("")
+    [<p#hello.hello>]
+    >>> p.append("hey there !")
+    [<p#hello.hello>]
+    >>> p.text()
+    ''
+
 And you can get back the modified html
 
     >>> print d
     ...style="font-size: 17px"...
     </html>
 
+
+
 For more documentation about the API use the jquery website http://jquery.com/
 
 You can run the doctests that you just read by running the test function or by
             if children:
                 tag.extend(children)
             tag.text = root.text
+            tag.tail = root.tail
         return self
 
     def text(self, value=None):
             tag.text = value
         return self
 
+    ################
+    # Manipulating #
+    ################
+
+    def append(self, value):
+        root = etree.fromstring('<root>' + value + '</root>')
+        children = root.getchildren()
+        for tag in self:
+            tag.text += root.text
+            tag.extend(children)
+            if tag.tail and root.tail:
+                tag.tail += root.tail
+            elif root.tail:
+                tag.tail = root.tail
+        return self
+
 
 def test():
     import doctest