如题,现在可以读取xml文件,使用getElementsByTagName()读取的话会读取所有元素
xml文件结构为:<station id="LR1">
<operation>JobId</operation>
<operation>PostId</operation>
</station><station id="LR2">
<operation>accountName</operation>
</station>
如何根据station的id获取指定的值呢
比如我根据id  "LR1" 去获取JobId,PostId这两个值?xml根据Id获取JavaWeb取值

解决方案 »

  1.   

    Element picLinks = (Element) doc.selectSingleNode("//station[@id='LR1']");
      

  2.   

    LZ使用什么读取的?
    可以看看dom4j,应该可以实现
      

  3.   

    List<Element> picLinks = (Element) doc.selectNodes("//station[@id='LR1']/operation");
    应该是这样
      

  4.   


    doc.selectSingleNode这个方法貌似在Document对象里面没找到...
    是用JAVA代码读取的.
      

  5.   

    我是这样子读取的..
       Document doc = builder.parse(filePath+"huidui.xml");   
                doc.normalize();   
                NodeList links = doc.getElementsByTagName("station");  
      

  6.   


    0.0 你们的document对象是引用的什么jar包的.
    为毛我的没这方法都..我是引用的这个import org.w3c.dom.Document;
      

  7.   

    9楼都说了dom4j,lz可以看看dom4j的xpath获取节点