Discussion:
Validate XML in a ForEach Loop
(too old to reply)
Osolage
2008-03-06 21:41:09 UTC
Permalink
Hi,

Last week, I tried very unsuccessfully to loop through a set of files
in a folder and validate whether they validated against either of two
different XML schemas. The situation was this:

* I had no control over the names of the files, so I couldn't filter
by file name
* I had to validate each file against both schemas to determine path
I'd take with the file
* The files could be intermingled amongst the whole set of files, so
there was no way for me to sort/filter

So I built a little SSIS package using a ForEach Loop control flow
task. In the loop, I had a XML task set to validate against one
schema. I then had another XML task set to validate against the other
schema. I had two variables scoped at the ForEach Loop that would
indicate which schema the file validated against. The variables were
defined as strings. I had the XML tasks save the validation result to
each of the variables and had them set to overwrite the value each
time.

Now, let's say the files actually play out in the following order:

File 1) Conforms to schema A
File 2) Conforms to schema B
File 3) Conforms to schema A
File 4) Conforms to schema B

The problem arises when I get to file 3. The variable for IsSchemaA
was already set to false when file #2 was checked. For some reason,
after validating file #3 against SchemaA, the value of IsSchemaA still
= false. The same thing happens when file #4 runs - in that case,
where the value of the IsSchemaB variable SHOULD be true, it evaluates
to false.

Has anyone run into this problem before? Is there a workaround? Was
SSIS not meant to perform this type of task?

Thanks in advance for your help.

Sincerely,
Osolage
Paul Clark
2011-02-14 10:13:16 UTC
Permalink
Hello Osolage,

I have been struggling to find a solution to exactly identical to yours describe in your post. If you ever found a solution for this it would be a great help if you were able to explain your approach.

Many thanks,
Paul
Post by Osolage
Hi,
Last week, I tried very unsuccessfully to loop through a set of files
in a folder and validate whether they validated against either of two
* I had no control over the names of the files, so I couldn't filter
by file name
* I had to validate each file against both schemas to determine path
I'd take with the file
* The files could be intermingled amongst the whole set of files, so
there was no way for me to sort/filter
So I built a little SSIS package using a ForEach Loop control flow
task. In the loop, I had a XML task set to validate against one
schema. I then had another XML task set to validate against the other
schema. I had two variables scoped at the ForEach Loop that would
indicate which schema the file validated against. The variables were
defined as strings. I had the XML tasks save the validation result to
each of the variables and had them set to overwrite the value each
time.
File 1) Conforms to schema A
File 2) Conforms to schema B
File 3) Conforms to schema A
File 4) Conforms to schema B
The problem arises when I get to file 3. The variable for IsSchemaA
was already set to false when file #2 was checked. For some reason,
after validating file #3 against SchemaA, the value of IsSchemaA still
= false. The same thing happens when file #4 runs - in that case,
where the value of the IsSchemaB variable SHOULD be true, it evaluates
to false.
Has anyone run into this problem before? Is there a workaround? Was
SSIS not meant to perform this type of task?
Thanks in advance for your help.
Sincerely,
Osolage
Submitted via EggHeadCafe
Statistics, Probability, Lotteries and Dumb Programmers
http://www.eggheadcafe.com/tutorials/aspnet/041de19a-e704-468f-bd3c-79164fc739f5/statistics-probability-lotteries-and-dumb-programmers.aspx
Loading...