Question How to replace xml content in conditionally selected elements using linq

corsair_moran

New member
Joined
Mar 22, 2009
Messages
1
Programming Experience
1-3
I'm working on a .NET application (VB 2008) that gets all of its data from a web-based Django application.

I'm using Linq-to-XML and Linq-to-objects in the app.

One API call is giving me XML data in the following form that I am loading into an XDocument.

<object pk="1" model="app.person">
<field type="CharField" name="reference_num">001</field>
<field to="app.office" name="office" rel="ManyToOneRel">2</field>
<field type="DateField" name="date">2008-09-03</field>
<field type="CharField" name="surname"></field>
<field type="CharField" name="name">Sandra</field>
<field type="DateField" name="birthdate">1988-11-03</field>
<field type="CharField" name="sex">F</field>
<field type="CharField" name="marital_status">S</field>
<field type="TextField" name="special_interests">Biking</field>
<field type="CharField" name="identity_proof"></field>
<field type="CharField" name="identity_proof_number"></field>
<field type="BooleanField" name="is_active">0</field>
<field type="DateTimeField" name="created">2008-09-03 12:46:39</field>
<field type="DateTimeField" name="modified">2008-09-03 12:46:39</field>
<field type="DateField" name="important_date"><None></None></field>
<field type="DateField" name="archive_date"><None></None></field>
<field type="CharField" name="process_status"></field>
<field type="FileField" name="image"></field>
<field to="auth.user" name="self_user" rel="OneToOneRel">13</field>
</object>

This is the format, the API call returns several "<object>" elements like this one. This XML contains "<None></None>" to represent Null values, for example, towards the bottom, in "<field type="DateField" name="important_date"><None></None></field>" . Other "<object>" elements in this XDocument may have valid dates or "<None></None>"

What I would like to do is this: for all "<objects>" where '<field type="DateField" name="important_date">' contains "<None></None>" replace this "<None></None>" null representation with 1899-01-01.

How would I go about achieving this?

Thanks.
 
Back
Top