如何使用c#asp.net从xml文件中删除XmlNode而不使用循环 [英] How to remove an XmlNode from xml file using c# asp.net with out looping

查看:69
本文介绍了如何使用c#asp.net从xml文件中删除XmlNode而不使用循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

推荐答案

将xml加载到xml文档中。

然后你可以使用 RemoveChild 直接删除节点。



这是一个示例 - XmlNode.RemoveChild方法 [ ^ ]。
Load the xml into an xml document.
You can then directly remove nodes using RemoveChild.

Here is an example - XmlNode.RemoveChild Method [^].


您可以使用LINQ。 (System.Xml.Linq)



You can use LINQ. (System.Xml.Linq)

XDocument xd = new XDocument();
xd.Parse(@"
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
");

XElement xe = xd.Root.Element("from");   // Returns the first node with the name "from"
xe.Remove();


我有一个xml文件名作为file.xml

i have one xml file name as file.xml
<NewDataSet>
  <Table>
    <ID>6</ID>
    <DateInserted>1900-01-01T00:00:00+05:30</DateInserted>
  </Table>
  <Table>
    <ID>1</ID>
    <DateInserted>1900-01-01T00:00:00+05:30</DateInserted>
  </Table>
  <Table>
    <ID>2</ID>
    <DateInserted>2014-07-04T11:14:28.233+05:30</DateInserted>
  </Table>
  <Table>
    <ID>3</ID>
    <DateInserted>2014-07-04T11:19:10.58+05:30</DateInserted>
  </Table>
  <Table>
    <ID>4</ID>
    <DateInserted>2014-07-04T11:19:22.487+05:30</DateInserted>
  </Table>
  <Table>
    <ID>5</ID>
    <DateInserted>2014-07-04T11:20:07.83+05:30</DateInserted>
  </Table>
</NewDataSet>





i想删除节点为此动态



i want to remove the nodes for this dynamically


这篇关于如何使用c#asp.net从xml文件中删除XmlNode而不使用循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆