【问题标题】:Getting Error Attribute xsi:noNamespaceschemaLocation is not allowed获取错误属性 xsi:noNamespaceschemaLocation 是不允许的
【发布时间】:2020-09-25 23:31:03
【问题描述】:

我收到此错误:

错误:(7, 50) cvc-complex-type.3.2.2: 属性“xsi:noNamespaceschemaLocation”不允许出现在元素“fieldsMapper”中。

我的 XML 文件如下:

<?xml version="1.0"?>
<fieldsMapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="https://www.company.com/core"
              xsi:noNamespaceschemaLocation="http://www.company.com/core/fieldsMapper fieldsMapper.xsd"
              sourceType="java.util.Map"
              targetType="com.company.integration.demo.Transaction"
              id="identityValidationInputMapper">
    <fields>
        <field name="msg_date1" type="Date">
            <sourceField name="msg_date" type="String" inputFormat="YYYYMMDD" default="20200407"/>
        </field>

        <field name="msg[msg_date]" type="String" outputFormat="YYMMDD">
            <sourceField name="msg_date" type="Date"/>
        </field>

        <field name="msg_date2" type="Date">
            <sourceField name="msg[msg_date]" type="String" inputFormat="YYYYMMDD"/>
        </field>

        <field name="output_array[2]" type="Date">
            <sourceField name="msg_date" type="String" inputFormat="YYYYMMDD"/>
        </field>

        <field name="smh_msg_date" type="Date">
            <sourceField name="input_array[2]" type="String" inputFormat="YYYYMMDD"/>
        </field>

        <field name="msg_text" type="String">
            <value>
                <![CDATA[
                    Characters with markup
                ]]>
            </value>
        </field>

        <field name="msg_constant_text" type="String">
            <value>NAH</value>
        </field>

        <field name="order_amount">
            <groovy>
                just groovy code
            </groovy>
        </field>
    </fields>
</fieldsMapper>

我的 fieldsMapper.xsd 如下:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
           elementFormDefault="qualified"
           targetNamespace="https://www.company.com/core" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="fieldsMapper" type="core:fieldsMapperType" xmlns:core="https://www.company.com/core"/>
  <xs:complexType name="sourceFieldType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute type="xs:string" name="name" use="optional"/>
        <xs:attribute type="xs:string" name="type" use="optional"/>
        <xs:attribute type="xs:string" name="inputFormat" use="optional"/>
        <xs:attribute type="xs:string" name="default" use="optional"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="fieldType">
    <xs:sequence>
      <xs:element type="core:sourceFieldType" name="sourceField" minOccurs="0" xmlns:core="https://www.company.com/core"/>
      <xs:element type="xs:string" name="value" minOccurs="0"/>
      <xs:element type="xs:string" name="groovy" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute type="xs:string" name="name" use="optional"/>
    <xs:attribute type="xs:string" name="type" use="optional"/>
    <xs:attribute type="xs:boolean" name="sasDate" use="optional"/>
    <xs:attribute type="xs:string" name="outputFormat" use="optional"/>
  </xs:complexType>
  <xs:complexType name="fieldsType">
    <xs:sequence>
      <xs:element type="core:fieldType" name="field" maxOccurs="unbounded" minOccurs="0" xmlns:core="https://www.company.com/core">
        <xs:annotation>
          <xs:documentation>Nested/Mapped field in a Java bean or Map as target  Nested/Mapped field in a Java bean or Map as source   Indexed field as target (in an array or List)   Indexed field as source (in an array or List)</xs:documentation>
        </xs:annotation>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="fieldsMapperType">
    <xs:sequence>
      <xs:element type="core:fieldsType" name="fields" xmlns:core="https://www.company.com/core"/>
    </xs:sequence>
    <xs:attribute type="xs:string" name="targetType"/>
    <xs:attribute type="xs:string" name="sourceType"/>
    <xs:attribute type="xs:string" name="id"/>
  </xs:complexType>
</xs:schema>

知道为什么我会收到此错误吗? XML 文件有效,XSD 文件也有效。我尝试将elementFormDefault 更改为unqualified 而不是qualified,但没有任何区别。

【问题讨论】:

    标签: xml xsd xml-parsing xsd-validation xml-validation


    【解决方案1】:

    对于初学者来说,

    xsi:noNamespaceschemaLocation
    

    应该是

    xsi:noNamespaceSchemaLocation
                   ^
    

    ...但是您甚至不应该使用xsi:noNamespaceSchemaLocation,因为您的 XML 位于命名空间中。请改用xsi:noNamespaceSchemaLocation

    改变

    xsi:noNamespaceschemaLocation="http://www.company.com/core/fieldsMapper 
                                   fieldsMapper.xsd"
    

    xsi:schemaLocation="http://www.company.com/core fieldsMapper.xsd"
    

    注意 xsi:schemaLocation 和命名空间的更改,以匹配 XML 的默认命名空间和 XSD 的 targetNamespace

    另请参阅

    【讨论】:

    • 我将其更改为 xsi:noNamespaceSchemaLocation="fieldsMapper.xsd" ,现在看来它正在工作。如果我执行 xsi:noNamespaceSchemaLocation="sas.com/boss/fieldsMapper fieldsMapper.xsd",我会得到 URI 未注册。
    • 你的 XML 有一个命名空间,所以你应该使用xsi:schemaLocation——不确定是什么软件在抱怨 URI 注册。我将添加一些适当的 Q/A 链接以及更多详细信息。
    猜你喜欢
    • 2016-08-11
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多