【发布时间】:2015-04-30 02:46:48
【问题描述】:
我想删除具有我从 Request.QueryString["removect"] 和特定用户 ID 下获得的值的城市节点,例如 <user Id="4/29/2015 6:11:34 PM">。
<Users>
<user Id="4/28/2015 11:29:44 PM">
<city>Moga</city>
<city>Rupnagar</city>
<city>Fatehgarh Sahib</city>
</user>
<user Id="4/29/2015 10:59:06 AM">
<city>Bathinda</city>
<city>Pathankot</city>
</user>
<user Id="4/29/2015 6:11:34 PM">
<city>Pathankot</city>
<city>Tarn Taran</city>
</user>
</Users>
我用来完成此操作的代码如下:
xmlDocument.Descendants("user").Where(x => (string)x.Attribute("Id") == usrCookieId)
.Elements("city")
.Where(x => (string)x.Value ==Request.QueryString["removect"]).Remove();
代码执行但没有任何反应。
【问题讨论】:
-
当然什么也没发生。您正在创建一个临时对象并从中删除内容。你没有分配它或任何东西。
-
我怎样才能实现删除相应节点的目标
-
尝试 .equals 并忽略大小写,向我们展示更多代码如何读取 xml 和其他内容。检查 xmlDocument.Descendants("user").Where(x => (string)x.Attribute("Id") == usrCookieId) .Elements("city") 计数