我正在使用XPath。我正在尝试比较存储在字符串中的值然后编写像
这样的查询XPathExpression desc_expr = xpath.compile("/algorithms/info[name=s]/description/text()");
其中s包含值并且是一个字符串。 我为此感到茫然。
但是,如果我写了像
这样的查询XPathExpression desc_expr = xpath.compile("/algorithms/info[name='somename']/description/text()");
然后查询工作。 字符串值的格式为abcd_abcd。它有一个特殊的字符_。因为特殊字符我得到一个空值吗? 任何人都可以帮助解决这个问题。 谢谢。
答案 0 :(得分:0)
变化
xpath.compile("/algorithms/info[name=s]/description/text()")
到
xpath.compile("/algorithms/info[name="+s+"]/description/text()")
你需要使用字符串连接来使用变量中的值。