Java XPath:选择具有特定属性名的类名元素
具有以下XML:Java XPath:选择具有特定属性名的类名元素,java,xml,spring-boot,xpath,Java,Xml,Spring Boot,Xpath,具有以下XML: <exceptions> <exception name="LegacyException" msg="ERREUR DU MODULE SERVEUR"> <context name="default" msg="ERREUR DU MODULE SERVEUR (%1$s) : %2$s" /> </exception> </exceptions> 如何通过
<exceptions>
<exception name="LegacyException" msg="ERREUR DU MODULE SERVEUR">
<context name="default" msg="ERREUR DU MODULE SERVEUR (%1$s) : %2$s" />
</exception>
</exceptions>
如何通过XPath选择异常名称和上下文名称
大概是这样的:
String className = "LegacyException";
String contextName= "default";
String query = "//exception[@name='" + className + "' and context[@name='" + contextName+ "']]";
XPathExpression<Element> xpe = XPathFactory.instance().compile(query, Filters.element());
String className=“LegacyException”;
字符串contextName=“默认”;
String query=“//异常[@name=”+className+“”和上下文[@name=”+contextName+“]]”;
XPathExpression xpe=XPathFactory.instance().compile(查询,Filters.element());
此xpath表达式
//exceptions/exception/@name
or
//exception/@name
评估为
default
法律例外
而这个
//exceptions/exception/context/@name
or
//context/@name
评估为
default
您是在寻找计算结果为
LegacyException
和default
的xpath表达式,还是其他表达式?@JackFleeting-yes