不允许获取错误属性 xsi:noNamespaceschemaLocation
Getting Error Attribute xsi:noNamespaceschemaLocation is not allowed
我收到这个错误:
Error:(7, 50) cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceschemaLocation' is not allowed to appear in element '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
但它没有任何区别。
首先,
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
。
另见
- How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?
我收到这个错误:
Error:(7, 50) cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceschemaLocation' is not allowed to appear in element '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
但它没有任何区别。
首先,
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
。
另见
- How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?