【发布时间】:2020-10-02 08:16:51
【问题描述】:
我在针对我的 XSD 验证 XML 时收到此错误。模式和实例都是有效的,我可以在 XML 解析器中验证它们,但在 Java 中出现此错误:
cvc-elt.1:找不到元素“fieldsMapper”的声明
以下是我的架构:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="https://www.company.com/mine" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="fieldsMapper" type="mine:fieldsMapperType" xmlns:mine="https://www.company.com/mine"/>
<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="mine:sourceFieldType" name="sourceField" minOccurs="0" xmlns:mine="https://www.company.com/mine"/>
<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="mine:fieldType" name="field" maxOccurs="unbounded" minOccurs="0" xmlns:mine="https://www.company.com/mine">
<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="mine:fieldsType" name="fields" xmlns:mine="https://www.company.com/mine"/>
</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 version="1.0" encoding="UTF-8"?>
<fieldsMapper xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.company.com/mine/fieldsMapper fieldsMapper.xsd"
xmlns="https://www.company.com/mine"
sourceType="java.util.Map"
targetType="java.util.Map"
id="identityValidationInputMapper">
<fields>
<field name="msg_date1" type="java.util.Date">
<sourceField name="msg_date" type="java.lang.String" inputFormat="yyyyMMdd" default="20200407"/>
</field>
<field name="msg_date2" type="java.util.Date">
<sourceField name="msg[msg_date_field]" type="java.lang.String" inputFormat="yyyyMMdd"/>
</field>
<field name="msg_date3" type="java.util.Date">
<sourceField name="input_array[0]" type="java.lang.String" inputFormat="yyyyMMdd"/>
</field>
<field name="msg_constant_text" type="java.lang.String">
<value>BLAH</value>
</field>
<field name="msg_text" type="java.lang.String">
<value>
<![CDATA[
Just a long text value
]]>
</value>
</field>
<field name="order_amount">
<groovy>
double taxPercent = sourceFields['tax_percent'] == null ? 5 : Double.valueOf(sourceFields['tax_percent'])
double txnAmount = sourceFields['txn_amount'] == null ? 0 : Double.valueOf(sourceFields['txn_amount'])
return taxPercent * txnAmount
</groovy>
</field>
<field name="msg_index" type="java.lang.Integer">
<sourceField name="input_index" type="java.lang.String" default="10"/>
</field>
</fields>
</fieldsMapper>
我尝试了很多模式位置和 xmlns 的变体,但无论我尝试什么,我都会收到该错误。
【问题讨论】:
标签: java spring-boot xsd xsd-validation xml-validation