XML Looping in C#

  • Thread starter Thread starter Intermediate-User
  • Start date Start date
I

Intermediate-User

Guest
Hi Team,


I have below format XML. I need to loop through and change the few attribute. Example Attribute <DiscPct /> . I need to update this to <DiscPct i:nil="true" />. Same way wherever XML attribute like<OptCD /> I need to change it to i:nil="true". Please help to implement.

<test xmlns="http://schemas.datacontract.org/2004/07/TEST" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ABC>
<name>Jack</name>
<fname>Jack S</fname>
</ABC>
<XYZ>
<Lan>English</Lan>
<Type>Low</Type>
</XYZ>
<Items>
<LItem>
<Employee>
<EmailAddress>test@gmail.com</EmailAddress>
<EmployeeNr i:nil="true" />
</Employee>
<DiscPct />
<OptCD/>
</LItem>
<LItem>
<Employee>
<EmailAddress>test@gmail.com</EmailAddress>
<EmployeeNr i:nil="true" />
</Employee>
<DiscPct />
<OptCD/>
</LItem>
</Items>
<BD>
<LBD>
<DiscPct/>
<Index>0</Index>
<BL>
<BLN>
<Date i:nil="true" />
<Desc>Sreenath</Desc>
</BLN>
</BL>
</LBD>
</BD>
</test>



My final XML after logic should be like this :

<test xmlns="http://schemas.datacontract.org/2004/07/TEST" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ABC>
<name>Jack</name>
<fname>Jack S</fname>
</ABC>
<XYZ>
<Lan>English</Lan>
<Type>Low</Type>
</XYZ>
<Items>
<LItem>
<Employee>
<EmailAddress>test@gmail.com</EmailAddress>
<EmployeeNr i:nil="true" />
</Employee>
<DiscPct i:nil="true" />
<OptCD i:nil="true" />
</LItem>
<LItem>
<Employee>
<EmailAddress>test@gmail.com</EmailAddress>
<EmployeeNr i:nil="true" />
</Employee>
<DiscPct i:nil="true" />
<OptCD i:nil="true" />
</LItem>
</Items>
<BD>
<LBD>
<DiscPct i:nil="true" />
<Index>0</Index>
<BL>
<BLN>
<Date i:nil="true" />
<Desc>Sreenath</Desc>
</BLN>
</BL>
</LBD>
</BD>
</test>

Continue reading...
 
Back
Top