Python 从子节点之后的XML节点提取文本
我试图解析一个包含一些文本的节点的XML文档,然后声明一个子节点,然后再包含更多文本。例如,下面XML中的第二个“post”元素:Python 从子节点之后的XML节点提取文本,python,xml,elementtree,Python,Xml,Elementtree,我试图解析一个包含一些文本的节点的XML文档,然后声明一个子节点,然后再包含更多文本。例如,下面XML中的第二个“post”元素: <?xml version="1.0"?> <data> <post> this is some text </post> <post> here is some more text <quote> and a nested
<?xml version="1.0"?>
<data>
<post>
this is some text
</post>
<post>
here is some more text
<quote> and a nested node </quote>
and more text after the nested node
</post>
</data>
但不幸的是,唯一的结果是:
this is some text
here is some more text
请注意,我缺少文本,嵌套节点之后缺少更多文本
所以
这是有效的XML吗
如果是,如何使用ElementTree或其他Python XML库来实现所需的解析
如果没有,除了编写自己的解析器之外,还有什么关于解析XML的建议吗
啊,在这里找到了答案:
基本上,我必须使用子节点的.tail
属性来访问以前丢失的文本
this is some text
here is some more text