0

下記のPythonコードを使用して読み取っているXMLファイルに次のデータがあり、それをOutlookに書き込むと、Outlookに書き込まれると、すべてのデータが1行に出力されます。もう1つは、すべての行の最後にあるxmlファイルで「br」タグを使用して、各行を「br」と「/ br」で囲んでみましたが、何も機能しないようです。何か提案はありますか?XML

<rel_notes>
    1.)Please move to this build for all further test and development 
    activities .
    2.)Please use this as a basebuild to verify 
    compilation and sanity
    3.)Any CL that nees to be integrated must 
    have a CL
</rel_notes>

Pythonコード

from xml.etree import cElementTree as etree
tree = etree.parse(file)
Releasenotes = ('\n'.join(elem.text for elem in tree.iter('rel_notes')))

出力

Release notes: 1.)Please move to this build for all further test and development activities 2.)Please use this as a basebuild to verify compilation and sanity 3.)Any CL that nees to be integrated must have a CL
4

1 に答える 1

0

標準の XML Python lib は使用しませんが、lxmlより強力です (XPath のサポートなど)。それは基本的にあなたが望むように動作するように見えます:

>>> s = """<rel_notes>
    1.)Please move to this build for all further test and development 
    activities .
    2.)Please use this as a basebuild to verify 
    compilation and sanity
    3.)Any CL that nees to be integrated must 
    have a CL
</rel_notes>"""
>>> from lxml import etree
>>> root = etree.fromstring(s)
>>> root.text
'\n    1.)Please move to this build for all further test and development \n    activities .\n    2.)Please use this as a basebuild to verify \n    compilation and sanity\n    3.)Any CL that nees to be integrated must \n    have a CL\n'
>>> print root.text

    1.)Please move to this build for all further test and development 
    activities .
    2.)Please use this as a basebuild to verify 
    compilation and sanity
    3.)Any CL that nees to be integrated must 
    have a CL

>>> 
于 2012-11-05T08:50:49.457 に答える