下面是xml,我需要删除代码等于“ ZOOMLA”的Element SMS。我正在使用C#代码,如下所示,但它不起作用。并给我“对象引用错误”
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 ();
Run Code Online (Sandbox Code Playgroud)
<?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>
Run Code Online (Sandbox Code Playgroud)