how to validate mandatory fields in XML

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
rohit_mca2003
Participant
Posts: 41
Joined: Wed Oct 08, 2008 9:19 am

how to validate mandatory fields in XML

Post 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.
Rohit
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post 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
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply