An existing XML feed we consume has a lot of properties whose values can be missing, and we want to treat these as NULL not optional or empty values because it makes enforcing strict typing harder and messes up our auto code generation and so on.
For instance we might receive:
<LASTUPDATED/>
We have no formal XSD but are creating one ourselves... it might currently look like: <xs:element type="xs:dateTime" name="LASTUPDATED"/>
This doesn't validate against the XML shown (""
is not a valid dateTime
). Ideally it would instead have xsi:nil=true
in the XML (nillable and minOccurs XSD element attributes)
Since we don't control the feed, can I create a transform that will replace any <xxx/>
element with <myElement xsi:nil='true'/>
? Instead changing our XSD to use minOccurs
is not great because then we have to check if each element exists or not rather than just supporting NULL values.
The following should work.
This however, will also match
<LASTUPDATED></LASTUPDATED>
which is semantically identical to<LASTUPDATED />