below is the xml and i need to remove the Element SMS where code equals to "ZOOMLA". i am using C# code as below but it does not work. and gives me "object reference error"
XDocument doc = XDocument.Parse(xml);
XElement sms = (from xml2 in doc.Descendants("SMSList").Descendants("SMS")
where xml2.Attribute("Code").Value == code
select xml2).FirstOrDefault();
sms.Remove();
<?xml version="1.0" encoding="utf-16" ?>
- <Parent>
<ServiceList />
<VoiceList />
- <SMSList>
- <SMS>
<Code>ZOOMLA</Code>
<Name>Zoom Limited</Name>
<SubType>Prepaid</SubType>
- <Fields>
- <Field>
<ID>222</ID>
<Name>Charges</Name>
<CValue>1</CValue>
<Priority>0</Priority>
</Field>
</Fields>
</SMS>
</SMSList>
<DataList />
<LBCOffer />
</Parent>
No comments:
Post a Comment