XPath:选择具有特定属性名称的类名称元素

问题描述 投票:0回答:1

具有以下XML:

<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());
java xml spring-boot xpath
1个回答
0
投票
此xpath表达式

//exceptions/exception/@name or //exception/@name

评估为

LegacyException

与此同时

//exceptions/exception/context/@name or //context/@name

评估为

default

© www.soinside.com 2019 - 2024. All rights reserved.