dom4j的XPATH问题 [英] XPATH problem with dom4j

查看:74
本文介绍了dom4j的XPATH问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用dom4j覆盖XML中的值. XML看起来像这样:

I am using dom4j to overwrite a value in the XML. The XML looks like this:

<start>
    <name color="blue" time="555555">
        <element1 param="1">
            <value>value1</value>
            <value>value2</value>
            <value>value3</value>
        <element1>
    </name>

    <name color="blue" time="888888">
        <element2 param="1">
            <value>value1</value>
            <value>value2</value>
            <value>value3</value>
        <element1>
    </name>
</start>

我正在尝试通过以下方式对节点进行分区:

I am trying to semect nodes by:

List list= document.selectNodes("//element1[@timetime='555555']" );

,但列表返回null. 我想更改所有三个值,其中time="555555".

but the list returns null. I wanted to change all the 3 values where time="555555".

没有办法直接去那个节点.

Isn't there a way to directly go to that node.

请帮助.

推荐答案

要选择三个值,请使用:

to select the three values, use:

//name[@time='555555']/element1/value

如果该函数也返回null,则可能涉及默认的名称空间,这意味着您需要显示整个XML.

If that returns null as well, there may be a default namespace involved and that means you need to show your entire XML.

XPath很灵活,如果您愿意,可以这样表示:

XPath is flexible, if you want you can express the same like this:

//value[ancestor::name[1]/@time='555555']

这篇关于dom4j的XPATH问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆