【问题标题】:XPath: Select class name element with a specific attribute nameXPath:选择具有特定属性名称的类名称元素
【发布时间】:2019-10-28 15:58:00
【问题描述】:

具有以下 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());

【问题讨论】:

  • 您是在寻找计算结果为 LegacyExceptiondefault 的 xpath 表达式,还是其他?
  • @JackFleeting 是的

标签: java xml spring-boot xpath


【解决方案1】:

这个 xpath 表达式

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

计算为

遗留异常

这个

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

计算为

default

【讨论】:

    猜你喜欢
    • 2011-03-18
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-30
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多