from lxml import etree
root = etree.fromstring('<root><section>A<p>B</p>C<p>D</p>E</section></root>')
for section_child in root.find('section'):
section_child.tail = section_child.tail.lower()
print(etree.tounicode(root))
from lxml import etree
xml = '<a>aaaa1<b>bbbb</b>aaaa2<c>cccc</c>aaaa3</a>'
element = etree.fromstring(xml)
for text in element.xpath('text()'):
xml = xml.replace(f'>{text}<', f'>{text.upper()}<')
检查紧靠文本前面的完整标记的}将包含C和E
.tail
。因此,在<section>A<p>B</p>C<p>D</p>E</section>
中,两个<p>
元素的{示例:
结果:
^{pr2}$我从我发布的问题中得到了答案:Parse XML text in between elements within a root element
一个值得关注的问题是xml中的CDATA,但我想这不是html的问题。在
相关问题 更多 >
编程相关推荐