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>
xml.etree.ElementTree.
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 ⑤ {}
>>> 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>]
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