How to print the CDATA of .xml file?

Kevien Lee ironpythonster at gmail.com
Fri Oct 13 05:45:57 EDT 2006


---------- Forwarded message ----------
From: "Fredrik Lundh" <fredrik at pythonware.com>
To: python-list at python.org
Date: Fri, 13 Oct 2006 11:03:45 +0200
Subject: Re: How to print the CDATA of .xml file?
Kevien Lee wrote:

> when i use the minidom to parase the XML file,it would ignored the section
> of <![CDATA[.......]>
> the code is:
>
> _document=minidom.parse("filePath")
> _documnetList=_document.getElementsByTagName("NodeArgs")
> for _argNode in _documnetList:
>    print _argNode.nodeValue,_argNode.localName
>
> when it run. The nodeValue of the CDATA Section  is  always None,Is my
code
> error?

here's one way to do it, under Python 2.5:

   import xml.etree.ElementTree as ET

   tree = ET.parse(filename)

   for elem in tree.findall(".//NodeArgs"):
       print elem.findtext("Disp")
       print elem.findtext("BtmPane/Path")

</F>
------------------------------------------------

use Python 2.5 is easy and good, but is there any others  way under version
2.4?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061013/2bdd2174/attachment.html>


More information about the Python-list mailing list