diff --git a/xml.html b/xml.html index c774a44..1f91785 100755 --- a/xml.html +++ b/xml.html @@ -258,7 +258,7 @@ mark{display:inline} >>> tree = etree.parse('examples/feed.xml') >>> root = tree.getroot() >>> root -<Element {http://www.w3.org/2005/Atom}feed at cd1eb0> +<Element {http://www.w3.org/2005/Atom}feed at cd1eb0>
  1. The ElementTree library is part of the Python standard library, in xml.etree.ElementTree.
  2. The primary entry point for the ElementTree library is the parse() function, which can take a filename or a file-like object. This function parses the entire document at once. If memory is tight, there are ways to parse an XML document incrementally instead. @@ -277,13 +277,13 @@ mark{display:inline}
     # continued from the previous example
     >>> root.tag                        
    -'{http://www.w3.org/2005/Atom}feed'
    +'{http://www.w3.org/2005/Atom}feed'
     >>> len(root)                       
     8
     >>> for child in root:              
     ...   print(child)                  
     ... 
    -<Element {http://www.w3.org/2005/Atom}title at e2b5d0>
    +<Element {http://www.w3.org/2005/Atom}title at e2b5d0>
     <Element {http://www.w3.org/2005/Atom}subtitle at e2b4e0>
     <Element {http://www.w3.org/2005/Atom}id at e2b6c0>
     <Element {http://www.w3.org/2005/Atom}updated at e2b6f0>
    @@ -309,13 +309,13 @@ mark{display:inline}
     >>> root.attrib                           
     {'{http://www.w3.org/XML/1998/namespace}lang': 'en'}
     >>> root[4]                               
    -<Element {http://www.w3.org/2005/Atom}link at e181b0>
    +<Element {http://www.w3.org/2005/Atom}link at e181b0>
     >>> root[4].attrib                        
     {'href': 'http://diveintomark.org/',
      'type': 'text/html',
      'rel': 'alternate'}
     >>> root[3]                               
    -<Element {http://www.w3.org/2005/Atom}updated at e2b4e0>
    +<Element {http://www.w3.org/2005/Atom}updated at e2b4e0>
     >>> root[3].attrib                        
     {}
      @@ -337,7 +337,7 @@ mark{display:inline} >>> tree = etree.parse('examples/feed.xml') >>> root = tree.getroot() >>> root.findall('{http://www.w3.org/2005/Atom}entry') -[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>, +[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>, <Element {http://www.w3.org/2005/Atom}entry at e2b510>, <Element {http://www.w3.org/2005/Atom}entry at e2b540>] >>> root.tag @@ -354,7 +354,7 @@ mark{display:inline}
       >>> tree.findall('{http://www.w3.org/2005/Atom}entry')    
      -[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>,
      +[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>,
        <Element {http://www.w3.org/2005/Atom}entry at e2b510>,
        <Element {http://www.w3.org/2005/Atom}entry at e2b540>]
       >>> tree.findall('{http://www.w3.org/2005/Atom}author')   
      @@ -394,7 +394,7 @@ mark{display:inline}
       
       >>> all_links = tree.findall('//{http://www.w3.org/2005/Atom}link')  
       >>> all_links
      -[<Element {http://www.w3.org/2005/Atom}link at e181b0>,
      +[<Element {http://www.w3.org/2005/Atom}link at e181b0>,
        <Element {http://www.w3.org/2005/Atom}link at e2b570>,
        <Element {http://www.w3.org/2005/Atom}link at e2b480>,
        <Element {http://www.w3.org/2005/Atom}link at e2b5a0>]
      @@ -426,13 +426,13 @@ mark{display:inline}
       # continuing from the previous example
       >>> it = tree.getiterator('{http://www.w3.org/2005/Atom}link')  
       >>> next(it)                                                    
      -<Element {http://www.w3.org/2005/Atom}link at 122f1b0>
      +<Element {http://www.w3.org/2005/Atom}link at 122f1b0>
       >>> next(it)
      -<Element {http://www.w3.org/2005/Atom}link at 122f1e0>
      +<Element {http://www.w3.org/2005/Atom}link at 122f1e0>
       >>> next(it)
      -<Element {http://www.w3.org/2005/Atom}link at 122f210>
      +<Element {http://www.w3.org/2005/Atom}link at 122f210>
       >>> next(it)
      -<Element {http://www.w3.org/2005/Atom}link at 122f1b0>
      +<Element {http://www.w3.org/2005/Atom}link at 122f1b0>
       >>> next(it)
       Traceback (most recent call last):
         File "<stdin>", line 1, in <module>
      @@ -455,7 +455,7 @@ StopIteration
      >>> tree = etree.parse('examples/feed.xml') >>> root = tree.getroot() >>> root.findall('{http://www.w3.org/2005/Atom}entry') -[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>, +[<Element {http://www.w3.org/2005/Atom}entry at e2b4e0>, <Element {http://www.w3.org/2005/Atom}entry at e2b510>, <Element {http://www.w3.org/2005/Atom}entry at e2b540>]
        @@ -478,15 +478,15 @@ except ImportError: >>> import lxml.etree >>> tree = lxml.etree.parse('examples/feed.xml') >>> tree.findall('//{http://www.w3.org/2005/Atom}*[@href]') -[<Element {http://www.w3.org/2005/Atom}link at eeb8a0>, +[<Element {http://www.w3.org/2005/Atom}link at eeb8a0>, <Element {http://www.w3.org/2005/Atom}link at eeb990>, <Element {http://www.w3.org/2005/Atom}link at eeb960>, - <Element {http://www.w3.org/2005/Atom}link at eeb9c0>] + <Element {http://www.w3.org/2005/Atom}link at eeb9c0>] >>> tree.findall("//{http://www.w3.org/2005/Atom}*[@href='http://diveintomark.org/']") -[<Element {http://www.w3.org/2005/Atom}link at eeb930>] +[<Element {http://www.w3.org/2005/Atom}link at eeb930>] >>> NS = '{http://www.w3.org/2005/Atom}' >>> tree.findall('//{NS}author[{NS}uri]'.format(NS=NS)) -[<Element {http://www.w3.org/2005/Atom}author at eeba80>, +[<Element {http://www.w3.org/2005/Atom}author at eeba80>, <Element {http://www.w3.org/2005/Atom}author at eebba0>]
        1. In this example, I’m going to import lxml.etree (instead of, say, from lxml import etree), to emphasize that these features are specific to lxml. @@ -504,7 +504,7 @@ except ImportError: >>> entries = tree.xpath("//atom:category[@term='accessibility']/..", ... namespaces=NSMAP) >>> entries -[<Element {http://www.w3.org/2005/Atom}entry at e2b630>] +[<Element {http://www.w3.org/2005/Atom}entry at e2b630>] >>> entry = entries[0] >>> entry.xpath('./atom:title/text()', namespaces=nsmap) ['Accessibility is a harsh mistress'] @@ -633,7 +633,7 @@ lxml.etree.XMLSyntaxError: Entity 'hellip' not defined, line 3, column 28 >>> parser.error_log examples/feed-broken.xml:3:28:FATAL:PARSER:ERR_UNDECLARED_ENTITY: Entity 'hellip' not defined >>> tree.findall('{http://www.w3.org/2005/Atom}title') -[<Element {http://www.w3.org/2005/Atom}title at ead510>] +[<Element {http://www.w3.org/2005/Atom}title at ead510>] >>> title = tree.findall('{http://www.w3.org/2005/Atom}title')[0] >>> title.text 'dive into '