Friday, 9 August 2013

How do I remove null properties from xml?

How do I remove null properties from xml?

Background: I am loading a class from a file through XamlReader.Load(),
working with it and then saving it back to a file through
XamlWriter.Save(). The original file has no null properties, but the
resulting saved file has all properties whether or not they are null, and
it bloats the file. So I would like to remove them before actually saving
to disk.
I have the following xml fragment as a string. I need to remove all
properties which have "{assembly:Null}" as the value.
<ElementMap ElementType="SegmentData"
Key="{assembly:Null}"
EntityPropertyMapping="SenderCode"
Name="Application Sender's Code"
ElementCode="GS02"
EdiDataType="AN"
EntityDataType="String"
MinLength="2"
MaxLength="15"
Position="0"
ElementIndex="2"
ValidateData="False"
Parent="{assembly:Null}"
IsRequired="True"
Note="{assembly:Null}"
Default="{assembly:Null}"
Example="{assembly:Null}"
ExcludeFromStringOutput="False" />
The end result would be:
<ElementMap
ElementType="SegmentData"
EntityPropertyMapping="SenderCode"
Name="Application Sender's Code"
ElementCode="GS02"
EdiDataType="AN"
EntityDataType="String"
MinLength="2"
MaxLength="15"
Position="0"
ElementIndex="2"
ValidateData="False"
IsRequired="True"
ExcludeFromStringOutput="False" />
So how can this be achieved?
Greg

No comments:

Post a Comment