From bbbbe0bde4cbd87c2be0ebdeae072f1d12ebf10f Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Wed, 20 May 2009 17:52:59 -0400 Subject: [PATCH] finished attributes-are-dictionaries section in xml chapter --- xml.html | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/xml.html b/xml.html index 03b5547..59754d2 100644 --- a/xml.html +++ b/xml.html @@ -298,19 +298,7 @@ mark{display:inline}

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. -

To refresh your memory, here is the first few lines of feed.xml, the XML document we’re working with. - -

<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/"/>
-...
-<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
-FIXME
 # continuing from the previous example
 >>> root.attrib                           
 {'{http://www.w3.org/XML/1998/namespace}lang': 'en'}
@@ -325,11 +313,11 @@ FIXME
 >>> root[3].attrib                        
 {}
    -
  1. The attrib property is a dictionary of the element’s attributes. The original markup here was <feed xmlns -
  2. -
  3. -
  4. -
  5. +
  6. The attrib property is a dictionary of the element’s attributes. The original markup here was <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">. The xml: prefix refers to a built-in namespace that every XML document can use without declaring it. +
  7. The fifth child — [4] in a 0-based list — is the link element. +
  8. The link element has three attributes: href, type, and rel. +
  9. The fourth child — [3] in a 0-based list — is the updated element. +
  10. The updated element has no attributes, so its .attrib is just an empty dictionary.

Searching For Nodes Within An XML Document