java 如何将变量传递给 XPathExpression

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6259237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:03:27  来源:igfitidea点击:

how to pass a variable to an XPathExpression

javaandroidandroid-emulator

提问by artist

i want to pass the value of a variable in XPathExpression. I want to put the id value in a variable. How can I do that? Below is the code;

我想在 XPathExpression 中传递一个变量的值。我想把 id 值放在一个变量中。我怎样才能做到这一点?下面是代码;

XPathExpression expr = xpath.compile("//Number[@id=1]/Movies/text()");

Above, I want to put the value of id in a variable. I tried int num =1 but doesn't works. Thanks.

上面,我想把 id 的值放在一个变量中。我试过 int num =1 但不起作用。谢谢。

回答by Nick Campion

String yourArg= "1";
XPathExpression expr = xpath.compile("//Number[@id="+yourArg+"]/Movies/text()");