无法删除"xsi:nil"标签通过xslt [英] not able to remove tags that "xsi:nil" in them via xslt

查看:312
本文介绍了无法删除"xsi:nil"标签通过xslt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下xml,其中包含多个带有xsi:nil ="true"的xml标记.这些是基本上为空的标签.我无法使用/查找任何sxlt转换器从xml中删除这些标签并获取xml的其余部分.

I have following xml which contains several xml tags with xsi:nil="true". These are tags that are basically null. I am not able to use/find any sxlt transformer to remove these tags from the xml and obtain the rest of the 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:与元素类型消息"关联的属性"xsi:nil"的前缀"xsi"未绑定.

[Fatal Error] file2.xml:5:30: The prefix "xsi" for attribute "xsi:nil" associated with an element type "messages" is not bound.

没有声明名为"xsi"的前缀,您应该在根元素中指定它,例如:

is absence of prefix named "xsi" declared, you should specify it in root element such as:

<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...

更新

如果您无法更改从Web服务接收的xml文档,则可以尝试下一种方法(如果您可以接受此方法):

update

If you could not change xml document you're receiving from webservice, you could try next approach(if this approach is acceptable for you):

  1. 更改您的xslt文档以处理xml文档而无需指定元素前缀
  2. 设置namespaceAwarerel = "nofollow"> DocumentBuilderFactory 设置为false
  1. Change your xslt document to process xml documents without specifying element prefixes
  2. Set property namespaceAware of DocumentBuilderFactory to false

在此之后,您的变压器不应该抱怨

After this yout transformer shouldn't complain

这篇关于无法删除"xsi:nil"标签通过xslt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆