首页 > 解决方案 > 我无法编写正确的 Xpath 条件来获取 DOM4J 中的节点以执行教育任务;dasd2312 dsad213esada2 ddaasdas

问题描述

<?xml version="1.0"?>
    <music>
    <style type="rock">
        <band id="1">
            <name>Led Zeppelin</name>
            <genre>Hard Rock</genre>
            <cast>
                <artist type="vocal">Robert Plant</artist>
                <artist type="drums">John Bonham</artist>
                <artist type="bass">John Paul Jones</artist>
               <artist type="guitar">Jimmy Page</artist>
            </cast>
        </band>


        <band id="2">
            <name>Scorpions</name>
            <genre>Heavy Metal</genre>
            <cast>
                <artist type="rhythm guitar">Rudolf Schenker</artist>
                <artist type="lead guitar">Matthias Jabs</artist>
                <artist type="bass">Pawel Maciwoda</artist>
            </cast>
        </band>
    </style>
</music> 


     

I only need to change this line https://www.google.ru/search?q=ajnj&lr=&newwindow=1&sa=G&hl=ru&sxsrf=ALeKk01kgWRNvElYeXm0YUe7ZHdTAz6Mag:1610541612260&tbm=isch&source=iu&ictx=1&fir=xmiW7S4go2DcxM%252CoaO_EbjxGFa_FM%252C_&vet=1&usg=AI4_ -kQAxhgZyDoyq2TTuqUf50TSroofWw&ved=2ahUKEwilgceF95juAhXE4IUKHVCcBT0Q9QF6BAgOEAE&biw=1777&bih=876#imgrc=xmiW7S4go2DcxM

     List<Node> nodes = document.selectNodes("/music/style/band[genge[text()='Hard Rock']]/name");
     nodes.stream().map(n -> n.getStringValue()).forEach(System.out::println);    

标签: xmlxpathjdom

解决方案


推荐阅读