Sending XPath a variable from Java

后端 未结 3 681
旧巷少年郎
旧巷少年郎 2020-12-03 21:24

I have an XPath expression that searches for a static value. In this example, \"test\" is that value:

XPathExpression expr = xpath.compile(\"//doc[contains(.         


        
3条回答
  •  抹茶落季
    2020-12-03 22:12

    You don't need to evaluate Java (or whatever else PL variables in XPath). In C# (don't know Java well) I'll use:

        string XPathExpression = 
    "//doc[contains(., " + myVar.ToString() + ")]/*/text()";
    
        XmlNodelist result = xmlDoc.SelectNodes(XPathExpression);
    

提交回复
热议问题