XML Omit Null Value Elements w/ Hierarchy

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
gsbrown
Premium Member
Premium Member
Posts: 148
Joined: Mon Sep 23, 2002 1:00 pm
Location: USA

XML Omit Null Value Elements w/ Hierarchy

Post by gsbrown »

I'm working with an embedded element and I want the entire structure omitted if the child element is NULL. I have "Omit Null Elements" checked, but it's only removing the child element and leaving the parent element. Is there a way to code this or the XSD to remove both the child and parent elements if the child element value is null?

Code: Select all

<xs:element name="EMail">
  <xs:complexType>
    <xs:sequence>
      <xs:element type="xs:string" name="EMailAddress"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
If the EMailAddress value is NULL, that tag is getting omitted from my output, but I still get the "<EMail/>" tag output. How can I omit that one as well?
gsbrown
Premium Member
Premium Member
Posts: 148
Joined: Mon Sep 23, 2002 1:00 pm
Location: USA

Post by gsbrown »

:oops: BAH! Another case of "discovered the fix immediately after posting a forum question"!. Let me share what I did. Simply adding a MinOccurs="0" to the XSD omits the parent element if the child element is omitted.

Code: Select all

<xs:element name="EMail" minOccurs="0"> 
  <xs:complexType> 
    <xs:sequence> 
      <xs:element type="xs:string" name="EMailAddress"/> 
    </xs:sequence> 
  </xs:complexType> 
</xs:element>
Post Reply