Xpath,Java和变量 [英] Xpath, Java and variables
本文介绍了Xpath,Java和变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我目前的代码:
Document document2 = builder.parse(new FileInputStream("C:path to xml file.xml"));
Node theNode2 = (Node) xpath.evaluate("//*[@name='**variable here**']", document2, XPathConstants.NODE);
如果代码显示此处为变量,是否可以使用变量搜索XML文件?到目前为止,我只能对我正在搜索的内容进行硬编码,即:
Where the code says "variable here", is it possible to search the XML file with a variable? I've only been able to hardcode in the thing I'm searching for so far ie :
("//*[@name='happy']", document2, XPathConstants.NODE);
推荐答案
你的问题不是很明确,但我想你是什么希望能够做的是搜索某些东西,但不是硬编码这个变量名吗?
Your question is not very clear but i think what you want to be able to do is search for something but not hardcode this variable name?
String variable = "variable name";
Document document2 = builder.parse(new FileInputStream("C:path to xml file.xml"));
Node theNode2 = (Node) xpath.evaluate("//*[@name='" + variable+"']", document2, XPathConstants.NODE);
这篇关于Xpath,Java和变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文