Thank you so much Dave,<br><br>This is very helpful. Have a happy holiday.<br><br>Mike<br><br><div><span class="gmail_quote">On 12/24/05, <b class="gmail_sendername">Dave Kuhlman</b> <<a href="mailto:dkuhlman@cutter.rexx.com">
dkuhlman@cutter.rexx.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Fri, Dec 23, 2005 at 03:53:33PM -0500, Michael Gilbert wrote:
<br>> Hello again,<br>><br>> I think I found a way to accomplish my goal with minidom. Is this the most<br>> direct solution for my goal, or is there a simpler way? Thanks again.<br><br>minidom is a good choice because it is part of the standard Python
<br>library. If you, or your users, are willing to install extra<br>software, you may want to look at ElementTree and lxml:<br><br>- ElementTree: <a href="http://effbot.org/zone/element-index.htm">http://effbot.org/zone/element-index.htm
</a><br><br>- lxml: <a href="http://codespeak.net/lxml/">http://codespeak.net/lxml/</a><br><br>They are DOM-like, but some consider it a better DOM.<br><br>><br>> import xml.dom.minidom<br>><br>> document = '<user first="jean" last="valjean" dob="17290101" children="1"
<br>> hobby="stealing bread" />'<br>><br>> dom = xml.dom.minidom.parseString(document)<br>><br>> t = dom.getElementsByTagName("user")[0]<br>><br>> if t.hasAttributes():<br>> for cnt in range(0,
t.attributes.length):<br>> if t.attributes.item(cnt).nodeName == "hobby":<br>> print 'hobby = ' + t.attributes.item(cnt).nodeValue<br><br>Yes. But, there may be a slightly more direct way. minidom
<br>attributes are a NamedNodeMap which is a sort of dictionary-like<br>object. So you can use indexing, for example, in your case,<br>something like:<br><br> t.attributes['hobby']<br><br>and also:<br><br> if t.attributes.has_key
('hobby'):<br> val = t.attributes['hobby']<br><br>Use dir(t.attributes) to get a list of other methods.<br><br>Dave<br><br>[snip]<br><br>--<br>Dave Kuhlman<br><a href="http://www.rexx.com/~dkuhlman">http://www.rexx.com/~dkuhlman
</a><br>_______________________________________________<br>XML-SIG maillist - <a href="mailto:XML-SIG@python.org">XML-SIG@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/xml-sig">http://mail.python.org/mailman/listinfo/xml-sig
</a><br></blockquote></div><br>