[英]XPath: Select class name element with a specific attribute name
Having the following XML:具有以下 XML:
<exceptions>
<exception name="LegacyException" msg="ERREUR DU MODULE SERVEUR">
<context name="default" msg="ERREUR DU MODULE SERVEUR (%1$s) : %2$s" />
</exception>
</exceptions>
How do I select exception name and context name via XPath?如何通过 XPath select 异常名称和上下文名称?
Something like this:像这样的东西:
String className = "LegacyException";
String contextName= "default";
String query = "//exception[@name='" + className + "' and context[@name='" + contextName+ "']]";
XPathExpression<Element> xpe = XPathFactory.instance().compile(query, Filters.element());
This xpath expression这个 xpath 表达式
//exceptions/exception/@name
or
//exception/@name
evaluates to评估为
LegacyException
遗留异常
while this one而这个
//exceptions/exception/context/@name
or
//context/@name
evaluates to评估为
default
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.