Python3:解析xml以获取具有特定孙子代的孩子

时间:2019-03-20 19:39:55

标签: xml python-3.x xpath lxml elementtree

我正在寻找一种写出具有特定给定值的xml子级的子级的方法。有没有一种方法可以将Xpath中的.findall()与某种逻辑AND和OR组合在一起? (当然还有其他方法)

示例:我想将以下xml的分开:其中 title =计算机词典 AND (价格= 24.95 页面= 513)

    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
    <book>
        <title>The Iliad and The Odyssey</title>
        <price>24.95</price>
        <pages>513</pages>
        <comments>
            <userComment rating="4"> Best translation I've read. </userComment>
            <userComment rating="2"> I like other versions better. </userComment>
        </comments>
    </book>
    <book>
        <title>Anthology of World Literature</title>
        <price>24.95</price>
        <pages>86</pages>
        <comments>
            <userComment rating="3"> Needs more modern literature. </userComment>
            <userComment rating="4"> Excellent overview of world literature. </userComment>
        </comments>
    </book>
    <book>
        <title>Computer Dictionary</title>
        <price>24.95</price>
        <pages>513</pages>
        <comments>
            <userComment rating="3"> A valuable resource. </userComment>
        </comments>
    </book>
    <book>
        <title>Cooking on a Budget</title>
        <price>24.95</price>
        <pages>56</pages>
        <comments>
            <userComment rating="4">Delicious!</userComment>
        </comments>
    </book>
    <book>
        <title>Great Works of Art</title>
        <price>24.95</price>
        <pages>83</pages>
    </book>
    <book>
        <title>Computer Dictionary</title>
        <price>213.95</price>
        <pages>311</pages>
        <comments>
            <userComment rating="3"> A valuable resource. </userComment>
        </comments>
    </book>
</bookstore>

使用python甚至可能吗?已经使用Xpath和ElementTree尝试了几个小时。帮助将不胜感激!

0 个答案:

没有答案
相关问题