【问题标题】:XPATH not working ns2:namespace preifix not defined errorXPATH 不工作 ns2:命名空间前缀未定义错误
【发布时间】:2015-01-08 01:10:04
【问题描述】:

您好我正在尝试使用 xpath /ns0:Start/ns0:Area/ns0:Test/ns0:Identifier/ns2:UniqueID 提取 UniqueID 的值,但它不起作用请帮助我,我需要正常的 xpath 以及MEL 命令

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Start xmlns:ns0="http://www.example.com/xmlns/9/Test">
  <ns0:Area>
    <ns0:Test>
      <ns0:Identifier>
        <ns2:UniqueID xmlns:ns2="http://www.example.com/xmlns/9/foundation">123456</ns2:UniqueID>
      </ns0:Identifier>
    </ns0:Test>
    <ns0:Test>
      <ns0:Identifier>
        <ns2:ExternalOrderID xmlns:ns2="http://www.example.com/xmlns/9/foundation">external</ns2:ExternalOrderID>
      </ns0:Identifier>
      <ns0:Info>
        <ns0:Status>st</ns0:Status>
      </ns0:Info>
    </ns0:Test>
  </ns0:Area>
</ns0:Start>

【问题讨论】:

  • 您需要告诉您的 XPath 代码您的前缀是什么意思 - 没有要求或假设 XPath 表达式中使用的前缀与 XML 文档中使用的前缀相同 - 即您可以使用exf 用于 http://www.example.com/xmlns/9/foundation 命名空间。
  • 你能告诉我如何为此编写一个 xpath
  • 我不熟悉你的工具,但我已经在在线测试器here 中放了一个例子 - 正如你所看到的,我故意使用不同的前缀来表明它们不问题 - 只有命名空间 URI 可以。

标签: xml xpath mule xslt-1.0 mule-studio


【解决方案1】:

正如 Victor 所说,您需要使用 mulexml:namespace-manager 作为命名空间:-

尝试以下方法:-

<mulexml:namespace-manager includeConfigNamespaces="true">
    <mulexml:namespace prefix="ns0" uri="http://www.example.com/xmlns/9/Test"/>
    <mulexml:namespace prefix="ns2" uri="http://www.example.com/xmlns/9/foundation"/>
</mulexml:namespace-manager>

然后使用以下 Xpath 检索 UniqueID :- #[xpath('//ns0:Start/ns0:Area/ns0:Test/ns0:Identifier/ns2:UniqueID').text]

ExternalOrderID :- #[xpath('//ns0:Start/ns0:Area/ns0:Test/ns0:Identifier/ns2:ExternalOrderID').text]

这会起作用:)

【讨论】:

    【解决方案2】:

    使用name space manager

    <mulexml:namespace-manager includeConfigNamespaces="true">
        <mulexml:namespace prefix="foo" uri="http://foo.com"/>
    </mulexml:namespace-manager>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      相关资源
      最近更新 更多