Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Handling Validation
- This topic has 2 replies, 1 voice, and was last updated 8 years, 10 months ago by
community-content.
-
AuthorPosts
-
-
June 25, 2009 at 8:00 AM #22718
Hope you can suggest some best way for what I am trying to achieve:
I have 3 schemas: 1 source and 2 Destinations
Source: Employees
Destination: Employees (valid records)
Destination: FailedMessages (all elements with description that failed validation)
I have source schema let say:
Employees
Employee
RecordID
UserID
FirstName
LastName
Address
Employee
RecordID
UserID
..
..
Employee
Employees
In destination I need to validate few criteria for each element e.g
FirstName –> can’t be empty; must contain A-Z, a-z
once each element is sucessfully validated, only thatrecord will be moved to destination.
If not, I need to put detail which element did not meet the criteria in second destination which is built to report what elements has issue and it should store:
<RecordID attribute>
<ElementName>
</ValidationError>
</ElementName>
<ElementName>
</ValidationError>
</ElementName>
<RecordID>
<RecordID>
<ElementName>
</ValidationError>
</ElementName>
</RecordID>
If FirstName for e.g has two criteria that must match and if it doesn;t, it should create two entries.
Any idea or suggestion how to achieve this?
Thanks,
rw -
June 29, 2009 at 3:36 AM #22729
There are a number of ways of validating an Xml message.
1. You can use schema validation, by defining the schema with the exact rules you require
e.g. using a regex pattern to constrain content
<xs:element name=”FirstName”>
<xs:simpleType>
<xs:restriction base=”xs:string”>
<xs:pattern value=”([a-zA-Z])*”/>
</xs:restriction>
</xs:simpleType>
</xs:element>You can then use a number of ways of performing the validation. The XmlDisassembler and XmlValidtor pipeline components will both perform validation, however they will both throw an exception on the first error and you will need to implement Route Message on Error functionality.
You can implement your own validation component (C# class library) that will continue past the first error and produce a list of all errors discovered, This can be run as a pipeline component (you will need to use Route Message on Error functionality) or from an orchestration.
2. An alternative is to use a Schematron pattern http://www.schematron.com/
This is my preferred approach as it provides more scope for validation, especially with loosely defined schemas that used for a number of different functions i.e. some elements may be defined as minOccurs = 0 but they may be reuired for some functions but not others – for example an Id field that is not required on a Add but is required for an update.
I typically skip using the Schematron language and processors (they don’t produce the output I require) and code my own Xslt.
I perform the validation inside an orchestration using a Transform shape or a dynamic transform. The put message is like this
<validation report errorcount=”1″>
<validationerror><xpath>/Employees/Employee/FirstName</xpath><message>Can only contain alpha characters</message></validationerror>
</validation report>After the map you can use a decide shape on errorcount and either send an error message or continue processing using the original message.
-
July 1, 2009 at 8:24 AM #22757
Thanks Greg!
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.