<Newslist>
<news Type="Exclusive">
<iNewsOfficeId>16</iNewsOfficeId>
<INewsPaperId>1</INewsPaperId>
<Data>2009-01-01</Data>
<title>白河社区吹拂和谐“春风”</title>
<sRefernceUrl>http://192.168.66.202:888/慈溪日报/20090407/page-001.xml@8</sRefernceUrl>
</news>
<news Type="Exclusive">
<iNewsOfficeId>16</iNewsOfficeId>
<INewsPaperId>1</INewsPaperId>
<Data>2009-01-01</Data>
<title>新能源产业振兴规划拆解 规划目标可能翻若干倍</title>
<sRefernceUrl>http://192.168.66.202:888/慈溪日报/20090407/page-001.xml@8</sRefernceUrl>
</news>
</Newslist>
我要根据title进行删除 比如根据 白河社区吹拂和谐“春风” 我要删除这个news里面的所有节点 高手赐教啊
<news Type="Exclusive">
<iNewsOfficeId>16</iNewsOfficeId>
<INewsPaperId>1</INewsPaperId>
<Data>2009-01-01</Data>
<title>白河社区吹拂和谐“春风”</title>
<sRefernceUrl>http://192.168.66.202:888/慈溪日报/20090407/page-001.xml@8</sRefernceUrl>
</news>
<news Type="Exclusive">
<iNewsOfficeId>16</iNewsOfficeId>
<INewsPaperId>1</INewsPaperId>
<Data>2009-01-01</Data>
<title>新能源产业振兴规划拆解 规划目标可能翻若干倍</title>
<sRefernceUrl>http://192.168.66.202:888/慈溪日报/20090407/page-001.xml@8</sRefernceUrl>
</news>
</Newslist>
我要根据title进行删除 比如根据 白河社区吹拂和谐“春风” 我要删除这个news里面的所有节点 高手赐教啊
{
DelXml("白河社区吹拂和谐“春风”");
}
void DelXml(string title)
{
XmlDocument xmlDoc = new XmlDocument();
string strPath = Server.MapPath("../xml/xmlfile.xml");
xmlDoc.Load(strPath);
XmlNode root = xmlDoc.SelectSingleNode("Newslist");
XmlNodeList xnl = xmlDoc.SelectSingleNode("Newslist").ChildNodes;
for (int i = 0; i < xnl.Count; i++)
{
XmlElement xe = (XmlElement)xnl.Item(i);
XmlNode xmlNode = xmlDoc.SelectSingleNode("Newslist/news/title");
if (xmlNode.InnerText == title)
{
root.RemoveChild(xe);
if (i < xnl.Count) i = i - 1;
}
}
xmlDoc.Save(strPath);
}
DelXMLByContext("白河社区吹拂和谐“春风” "); static void DelXMLByContext(string ctx)
{
XmlDocument doc = new XmlDocument();
string file = "~/xmlfile.xml";
doc.Load(file); XmlNode node = doc.SelectSingleNode(string.Format("//news[title='{0}']", ctx)); node.ParentNode.RemoveChild(node);
doc.Save(file);
}