我有以下 xml,其中包含多个带有 xsi:nil="true" 的 xml 标签。这些标签基本上是空的。我无法使用/找到任何 sxlt 转换器来从 xml 中删除这些标签并获取 xml 的其余部分。
<?xml version="1.0" encoding="utf-8"?>
<p849:retrieveAllValues xmlns:p849="http://package.de.bc.a">
<retrieveAllValues>
<messages xsi:nil="true" />
<existingValues>
<Values>
<value1> 10.00</value1>
<value2>123456</value2>
<value3>1234</value3>
<value4 xsi:nil="true" />
<value5 />
</Values>
</existingValues>
<otherValues xsi:nil="true" />
<recValues xsi:nil="true" />
</retrieveAllValues>
</p849:retrieveAllValues>
您收到错误的原因
[致命错误] file2.xml:5:30:与元素类型“messages”关联的属性“xsi:nil”的前缀“xsi”未绑定。
如果缺少声明名为“xsi”的前缀,则应在根元素中指定它,例如:
<p849:retrieveAllValues xmlns:p849="http://package.de.bc.a"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<retrieveAllValues>
<messages xsi:nil="true" />
// other code...
update
如果您无法更改从 Web 服务接收的 xml 文档,您可以尝试下一个方法(如果您可以接受此方法):
- 改变你的
xslt
document 处理 xml 文档而不指定元素前缀
- 设置属性
namespaceAware
of DocumentBuilderFactory http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setNamespaceAware%28boolean%29为假
在此之后你的变压器不应该抱怨
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)