5

I just started python and was trying to parse the xml file using ElementTree. But the problem is I have one tag with CDATA which is removed after tree.write.

So basically I had this tag

<content><![CDATA[eclipse.ver=1&encoding/ <project>=UTF-8${line.sep}]]></content>

which is change to

<content>eclipse.ver=1&encoding/&lt;project&gt;=UTF-8${line.sep}</content>

I tried google it but was not very helpful. So can anyone help me, how can I get exact same content within the tag??

The Red Devil
  • 51
  • 1
  • 5
  • Possible duplicate of http://stackoverflow.com/questions/174890/how-to-output-cdata-using-elementtree – Zixian Cai Oct 07 '16 at 03:43
  • 1
    I think this question is to output the xml file hardcoding the xml tags. But I want to edit my xml file which contains CDATA. – The Red Devil Oct 07 '16 at 03:51

1 Answers1

-4
from xml.etree.ElementTree import ElementTree
import re
l=[]
tree = ElementTree()
tree.parse("YOURFILE.xml")
root = tree.getroot()

for parent in root.findall('.//content/..'):
    for child in parent.findall("content"):
        if(child.text != None):
            l.append(child.text)