我正在使用模式验证使用XSD验证XML。 在调试模式下运行时,在模式验证后无法继续。 我通过下面的片段。
<flow name="xmlwithxsdofdbFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10000"/>
<db:select config-ref="Generic_Database_Configuration" doc:name="Database">
<db:parameterized-query>
<![CDATA[select * from tblcustomer where batch='N';]]>
</db:parameterized-query>
</db:select>
</poll>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload map
{
id : $.Id,
customerid : $.Customerid,
address : $.Address,
dob : $.Dob,
firstname : $.Firstname,
lastname : $.LastName,
middlename : $.Middlename,
phoneno : $.Phoneno,
batch : $.Batch,
recorddate : $.RecordDate
}]]>
</dw:set-payload>
</dw:transform-message>
<mulexml:object-to-xml-transformer doc:name="Object to XML"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
<mulexml:schema-validation-filter
schemaLocations="customer_validation.xsd"
returnResult="false" doc:name="Schema Validation"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
这是Xsd文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- XML Schema Generated from XML Document on -->
<!-- Fri Sep 02 2016 15:02:35 GMT+0530 (India Standard Time) -->
<!-- with XmlGrid.net Free Online Service http://xmlgrid.net -->
<xs:element name="Customer_schema_validation">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerData" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Id" type="xs:int"></xs:element>
<xs:element name="Customerid" type="xs:string"></xs:element>
<xs:element name="Address" type="xs:string" nillable="false"></xs:element>
<xs:element name="Dob" type="xs:date"></xs:element>
<xs:element name="Firstname" type="xs:string"></xs:element>
<xs:element name="LastName" type="xs:string"></xs:element>
<xs:element name="Middlename" type="xs:string"></xs:element>
<xs:element name="Phoneno" type="xs:string"></xs:element>
<xs:element name="Batch" type="xs:string"></xs:element>
<xs:element name="RecordDate" type="xs:date"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
答案 0 :(得分:1)
从您的代码生成的xml无效。您必须更改dataweave脚本。这对我来说很好用
<file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
<mulexml:schema-validation-filter schemaLocations="customer_validation.xsd" returnResult="false" name="Schema_Validation"
doc:name="Schema Validation" />
<flow name="testFlow">
<file:inbound-endpoint path="tmp" connector-ref="File" responseTimeout="10000" doc:name="File" mimeType="application/json"/>
<dw:transform-message metadata:id="aef6cf8e-4db2-4e6e-9838-81f7aedff827" doc:name="Transform Message">
<dw:input-payload mimeType="application/json"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
---
{
Customer_schema_validation: {
(payload map ((payload01 , indexOfPayload01) -> {
CustomerData: {
Id: payload01.Id,
Customerid: payload01.Customerid,
Address: payload01.Address,
Dob: payload01.Dob,
Firstname: payload01.Firstname,
LastName: payload01.LastName,
Middlename: payload01.Middlename,
Phoneno: payload01.Phoneno,
Batch: payload01.Batch,
RecordDate: payload01.RecordDate
}
}))
}
}]]></dw:set-payload>
</dw:transform-message>
<logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
<message-filter onUnaccepted="error_invalid_data" doc:name="Message">
<mulexml:schema-validation-filter schemaLocations="customer_validation.xsd" returnResult="false"/>
</message-filter>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
<flow name="error_invalid_data" >
<logger message="ERROR: MESSAGE PAYLOAD: #[message.payload]" level="INFO" doc:name="Logger" />
</flow>
当生成的文件无效时,这是将错误流程路由到错误流。
希望这有帮助。