【问题标题】:The prefix "xsi" for attribute "xsi:type" associated with an element type is not bound与元素类型关联的属性“xsi:type”的前缀“xsi”未绑定
【发布时间】:2020-04-05 17:33:04
【问题描述】:

我编写了 XSLT,但出现以下错误:

与元素类型 RemoteException 关联的属性 xsi:type 的前缀 xsi 未绑定。

我的输入 XML 是

<RemoteException xsi:type='ns1:Exception' xmlns:ns1='http://errorhandling.service.e2e.de'>
     <causeClass xsi:type='xsd:string'>de.common.exception.StringLengthException</causeClass>
     <causeMessage xsi:type='xsd:string'>lfdNr has invalid length: 11 (min: 14, max: 14, content: '035593111P0')</causeMessage>
     <causeStackTrace xsi:type='xsd:string'>at)</causeStackTrace>
     <errorCode xsi:type='xsd:int'>201</errorCode>
     <message xsi:type='xsd:string'>invalid length</message>
    </RemoteException>

XSLT 代码

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="xsl soap response ns1   xsi" 

xmlns:response="http://tempuri.org/" 

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ns1="http://errorhanlding.service.e2e..de" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <!-- Output -->
   <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
   <xsl:strip-space elements="*"/>
   <xsl:template match="/">

     <xsl:if test="//RemoteException">
         <Fault_MT_Test>
            <standard>
               <faultText>
                  <xsl:value-of select="//faultstring"/>
               </faultText>
               <faultUrl>
                  <xsl:value-of select="//faultcode"/>
               </faultUrl>
            </standard>
         </Fault_MT_Test>
      </xsl:if>

   </xsl:template>
</xsl:stylesheet>

能否请您解释一下这个错误是什么意思以及如何消除它?

【问题讨论】:

  • 错误是由您的输入引起的,而不是由您的 XSLT 引起的。
  • 谢谢迈克尔,我总是从合作伙伴那里得到这个错误格式,如果我不允许做 SOAP 信封

标签: xml xslt xsd xml-namespaces


【解决方案1】:

必须定义 XML 命名空间前缀,例如 xsi;否则,XML 的命名空间格式不正确。不控制 XML 也没关系。要么告诉你上游的人修复它(不可否认它是坏了),要么自己修复它。

要声明xsi,请添加以下内容:xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

另见

【讨论】:

    猜你喜欢
    • 2016-10-12
    • 2018-09-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    相关资源
    最近更新 更多