Reputation: 1694
I have a xml file like this
...
<text>
<font_option>true</font_option>
<font_size>5</font_size>
</text
...
I need to validate this xml file. If font_option
is true, then
the font_size
is mandatory, if font_option
is false,
then font_size
is optional.
How can I validate this in SSIS using xml task?
Upvotes: 1
Views: 2088
Reputation: 18950
There are two ways in SSIS for validating an XML file:
1) XML Task, easy but has some limitations
2) Script Task, more flexible bit requires some C#/.NET knowledge.
If you have a very complex XSD it might be necessary to use a script task and validate the XML file using code.
Regarding your question about a conditional constraint: The basic idea of XSD is to bind validation to element types. If you have one set of elements that should validate one way and another set another way, it's pretty clear that deal with two distinct types of elements. The simplest solution would be to make font_size mandatory. However, XSD 1.1 allows conditional required elements.
Upvotes: 2
Reputation: 71
Define a XSD schema file (How-To here) to the outer bounds of what you expect, and use the XML Task in the Control Flow.
http://msbitutorials.blogspot.com/2013/11/xml-task-in-ssis-with-example.html
Your conditional requirement on the second attribute is odd. If you're trying to constrain the values, you should do so 100% of the time, especially if you're attempting to load to a DB. You could then further route rows once in a data flow task.
Upvotes: 0