mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
finished attributes-are-dictionaries section in xml chapter
This commit is contained in:
@@ -298,19 +298,7 @@ mark{display:inline}
|
||||
|
||||
<p>XML isn’t just a collection of elements; each element can also have its own set of attributes. Once you have a reference to a specific element, you can easily get its attributes as a Python dictionary.
|
||||
|
||||
<p>To refresh your memory, here is the first few lines of <code>feed.xml</code>, the XML document we’re working with.
|
||||
|
||||
<pre><code><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
|
||||
<title>dive into mark</title>
|
||||
<subtitle>currently between addictions</subtitle>
|
||||
<id>tag:diveintomark.org,2001-07-29:/</id>
|
||||
<updated>2009-03-27T21:56:07Z</updated>
|
||||
<link rel="alternate" type="text/html" href="http://diveintomark.org/"/>
|
||||
<link rel="self" type="application/atom+xml" href="http://diveintomark.org/feed/"/>
|
||||
...</code></pre>
|
||||
<pre class=screen>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
|
||||
FIXME
|
||||
# continuing from the previous example
|
||||
<a><samp class=p>>>> </samp><kbd>root.attrib</kbd> <span>①</span></a>
|
||||
<samp>{'{http://www.w3.org/XML/1998/namespace}lang': 'en'}</samp>
|
||||
@@ -325,11 +313,11 @@ FIXME
|
||||
<a><samp class=p>>>> </samp><kbd>root[3].attrib</kbd> <span>⑤</span></a>
|
||||
<samp>{}</samp></pre>
|
||||
<ol>
|
||||
<li>The <code>attrib</code> property is a dictionary of the element’s attributes. The original markup here was <code><feed xmlns
|
||||
<li>
|
||||
<li>
|
||||
<li>
|
||||
<li>
|
||||
<li>The <code>attrib</code> property is a dictionary of the element’s attributes. The original markup here was <code><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"></code>. The <code>xml:</code> prefix refers to a built-in namespace that every XML document can use without declaring it.
|
||||
<li>The fifth child — <code>[4]</code> in a <code>0</code>-based list — is the <code>link</code> element.
|
||||
<li>The <code>link</code> element has three attributes: <code>href</code>, <code>type</code>, and <code>rel</code>.
|
||||
<li>The fourth child — <code>[3]</code> in a <code>0</code>-based list — is the <code>updated</code> element.
|
||||
<li>The <code>updated</code> element has no attributes, so its <code>.attrib</code> is just an empty dictionary.
|
||||
</ol>
|
||||
|
||||
<h2 id=xml-find>Searching For Nodes Within An XML Document</h2>
|
||||
|
||||
Reference in New Issue
Block a user