Page 1 of 1

how to validate mandatory fields in XML

Posted: Wed Nov 10, 2010 7:37 am
by rohit_mca2003
Hi,

I am working with the XML files and I have imported the XSD document. XSD has information of all the mandatory and non mandatory fields.

I want to have a check and trace while parsing XML in case XML document does not have mandatory field.

In example below

<body>
<text>
<id>123</id>
<name>ABCD</name>
</text>
<text>
<id>12345</id>
<name>ABC</name>
</text>
</body>

In normal case I get 2 records as:
123 ABCD
12345 ABC

But if I remove mandatory field 'id' in one of the segment then I get only 1 record.

Example XML:

<body>
<text>
<name>ABCD</name>
</text>
<text>
<id>12345</id>
<name>ABC</name>
</text>
</body>

Output:
12345 ABC

Could any one help me to trace the rejected record and how can I check the presence of mandatory field 'id' in XML document.

Thanks.

Posted: Wed Nov 10, 2010 10:02 am
by eostic
Sounds like you may have two different issues going on....

First, if an element is truly mandatory in the xsd, and the xsd is listed inside the header of the xml document (usually with an attribute something like NoNameSpaceSchemaLocation="<your fully qualified xsd>"), then you can check the "validate" option and have DataStage reject the xml before it is even fully parsed. That impacts performance though, so it's not always the best solution.

Your current scenario sounds more like the behavior of the stage concerning the "repetition element". If you have the ID column checked as a "key", then it is the repetition element, and will be controlled by the "Repetition element Required" check box. With it checked, if a node doesn't have it, then DS won't retrieve it.

If you uncheck the box, then you'll still get the row, but ID will be "null" downstream.

You could then check for nulls and do special things with those rows.

Ernie