Let's say, I have a xml file like this:
<recs>
<REC>
<SYS_TOPIC>topic1 topic1</SYS_TOPIC>
<SYS_AUTHORS>author1</SYS_AUTHORS>
<DOC_CONTENT>content1 content1 content1 content1 content1 content1 content1</DOC_CONTENT>
<DOC_WRITEDATE>2016-12-01 09:30:10</DOC_WRITEDATE>
</REC>
<REC>
<SYS_TOPIC>topic2 topic2</SYS_TOPIC>
<SYS_AUTHORS>author2</SYS_AUTHORS>
<DOC_CONTENT>content2 content2 content2 content2 content2 content2 content1</DOC_CONTENT>
<DOC_WRITEDATE>2016-12-01 09:30:10</DOC_WRITEDATE>
</REC>
</recs>
What if I wanna merge all the contents in the tag of <DOC_CONTENT>
together in one? I tried root.findall('DOC_CONTENT').text
But it consoles 'list' object has no attribute 'text'
import xml.etree.ElementTree as et
source_xml = """<recs>
<REC>
<SYS_TOPIC>topic1 topic1</SYS_TOPIC>
<SYS_AUTHORS>author1</SYS_AUTHORS>
<DOC_CONTENT>content1 content1 content1 content1 content1 content1 content1</DOC_CONTENT>
<DOC_WRITEDATE>2016-12-01 09:30:10</DOC_WRITEDATE>
</REC>
<REC>
<SYS_TOPIC>topic2 topic2</SYS_TOPIC>
<SYS_AUTHORS>author2</SYS_AUTHORS>
<DOC_CONTENT>content2 content2 content2 content2 content2 content2 content1</DOC_CONTENT>
<DOC_WRITEDATE>2016-12-01 09:30:10</DOC_WRITEDATE>
</REC>
</recs>"""
tree = et.fromstring(source_xml)
doc_content = "DOC_CONTENT"
content = [tr.text for tr in tree.iter() if (tr.tag ==doc_content)]
root = et.Element(doc_content)
root.text = ""
for el in content:
root.text += el