我有点问题。很久以前我为我们的生产系统编写了一个API,它使用了Apache XML Beans。模式是同构的(即没有导入,一切都来自同一模式),一切都运行得很好,即使API处理的代码非常冗长。我已经使用JAXB编写了一个更简单,更优雅的RESTful API,其中考虑了旧的一部分,即不同的模式,但有些元素是相同的。为了清理和简化旧API中的绑定代码,我通过删除它们并导入新模式并使用这些元素替换了一些部分。但是,每当我尝试解析使用新的模式混合的文档时,我都会从XML Bean中收到验证错误:

error: cvc-complex-type.2.4a: Expected element 'redundant-element@http://www.my.com/old/xmlns' instead of 'redundant-element@http://www.my.com/new/xmlns' here in element redundant-element-list@http://www.my.com/old/xmlns

以前有人遇到过这个吗?有任何解决方案或想法吗?我真的很感激。谢谢你。

有帮助吗?

解决方案 2

谢谢你的回复。我已尝试在文档的根目录和“冗余元素”本身上以多种排列方式显式添加新的命名空间。 IE:

<oldxmlns:root xmlns:oldxmlns="abc" xmnls:newxmlns="xyz">
      .....
</oldxmlns:root>

..和......

<oldxmlns:root xmlns:oldxmlns="abc">
   <oldxmlns:nested-element>
         .....
      <newxmlns:redundant-element xmnls:newxmlns="xyz">
           .....
      </newxmlns:redundant-element>
         .....
   </oldxmlns:nested-element>
</oldxmlns:root>

...我还尝试了许多与默认命名空间等的组合,但没有一个有效。

其他提示

看起来文档中的命名空间仍然是旧命名空间。没有模式和文档很难分辨。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top