【问题标题】:Unmarshalling an xml element which is not part of namespace解组不属于命名空间的 xml 元素
【发布时间】:2011-09-15 06:21:36
【问题描述】:

我有一个来自网络服务的 xml 响应:

<ns2:response xmlns:ns2="http://abc.com">
  <ns2:msgHeader>
    <ns2:empid>1234</ns2:empid>
    <ns2:empname>John</ns2:empid>
  </ns2:msgHeader>
  <error>
    <httpstatus>500</httpstatus>
    <description>Error while processing the request.Please contact customercare</description>
  </error>
</ns2:response>

当 xml 架构采用这种格式时,我如何解组。 &lt;error&gt; 是根元素 &lt;response&gt; 的一部分。

我正在使用 Restful 客户端并使用 resttemplate 向服务器发出请求。我的 applicationcontext.xml 使用 org.springframework.http.converter.xml.MarshallingHttpMessageConverter 编组和解组请求和响应 XML。

【问题讨论】:

    标签: java xml spring namespaces unmarshalling


    【解决方案1】:

    你有 xsd 吗?我认为元素应该在你的 xsd 中定义

    【讨论】:

      【解决方案2】:

      大概,您有​​一个response 元素的架构,其中它引用了error 元素,该元素位于一个单独的架构中(不幸的是,架构在同一个文件中不能有多个命名空间)。带有 error 元素的单独架构文件将没有 targetNamespace。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-12
        • 1970-01-01
        相关资源
        最近更新 更多