[@lm_id=3]只能是对属性的选择;
你的数据应为
<NewsSubject>
  <subject lm_id=1>
    <lm_name>人物</lm_name>
  </subject>
</NewsSubject>
using System;
using System.IO;
using System.Xml;public class Sample
{
  public static void Main()
  {      XmlDocument doc = new XmlDocument();
      doc.Load("booksort.xml");      //Create an XmlNamespaceManager for resolving namespaces.
      XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
      nsmgr.AddNamespace("bk", "urn:samples");      //Select the book node with the matching attribute value.
      XmlNode book;
      XmlElement root = doc.DocumentElement;
      book = root.SelectSingleNode("descendant::book[@bk:ISBN='1-861001-57-6']", nsmgr);      Console.WriteLine(book.OuterXml);  }
}[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;int main() {   XmlDocument* doc = new XmlDocument();
   doc -> Load(S"booksort.xml");   //Create an XmlNamespaceManager for resolving namespaces.
   XmlNamespaceManager* nsmgr = new XmlNamespaceManager(doc -> NameTable);
   nsmgr -> AddNamespace(S"bk", S"urn:samples");   //Select the book node with the matching attribute value.
   XmlNode * book;
   XmlElement * root = doc -> DocumentElement;
   book = root -> SelectSingleNode(S"descendant::book->Item[@bk:ISBN='1-861001-57-6']", nsmgr);   Console::WriteLine(book -> OuterXml);
}该示例使用文件 booksort.xml 作为输入。<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
  <book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
    <title>Pride And Prejudice</title>
    <author>
      <first-name>Jane</first-name>
      <last-name>Austen</last-name>
    </author>
    <price>24.95</price>
  </book>
  <book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
    <title>The Handmaid's Tale</title>
    <author>
      <first-name>Margaret</first-name>
      <last-name>Atwood</last-name>
    </author>
    <price>29.95</price>
  </book>
  <book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
    <title>Emma</title>
    <author>
      <first-name>Jane</first-name>
      <last-name>Austen</last-name>
    </author>
    <price>19.95</price>
  </book>
  <book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
    <title>Sense and Sensibility</title>
    <author>
      <first-name>Jane</first-name>
      <last-name>Austen</last-name>
    </author>
    <price>19.95</price>
  </book>
</bookstore>

解决方案 »

  1.   

    删除一个节点元素
       string itemname=this.listBox1.SelectedItem.ToString();
       
     
       this.listBox1.Items.Remove(this.listBox1.SelectedItem);
     
       //begin del xmlfile
       XmlDocument doc=new XmlDocument();
       doc.Load(xmlfile);
       
     
       XmlNodeList topM=doc.DocumentElement.ChildNodes;
       foreach(XmlElement element in topM)
       {
        if(element.Name==this.comboBox1.Text)
        {
     
         //得到该节点的子节点
         XmlNodeList nodelist=element.ChildNodes;      
     
         foreach(XmlElement el in nodelist)//读元素值
         {       
          if(el.Attributes["key"].Value==itemname)
          {
           element.RemoveChild(el);
          }
          }//循环元素
          
        }//得到组
     
       }//循环组
        doc.Save(xmlfile);  //一定要保存一下,否则不起作用
     
      

  2.   

    帮助上的例子我都看过。没有。
    能不能根据<lm_id>1</lm_id>
    选择到
    <subject>
        <lm_id>1</lm_id>
        <lm_name>人物</lm_name>
    </subject>
    结点,把相应的内容全部删除??
      

  3.   

    结合这两个方法用用了.RemoveAll 删除当前节点的所有子节点或属性
    ParentNode.RemoveChild(XmlNode)
      

  4.   

    XmlNode delNode = xmldoc.SelectSingleNode("NewsSubject/subject/lm_id[@lm_id=3]");
    xmldoc.DocumentElement.RemoveChild(delNode.ParentNode);-->XmlNode delNode = xmldoc.SelectSingleNode("NewsSubject/subject/[lm_id=3]");
    xmldoc.DocumentElement.RemoveChild(delNode);
      

  5.   

    我这样删除:
    for(int i=0;i<xmlnd.Count;i++)
    {
    String lm_id = xmlnd[i].SelectSingleNode("lm_id").InnerXml.Trim();
    if(lm_id=="1")
    {
    xmlnd[i].RemoveAll(); }
    }
    xmldoc.Save(xmlPath);
    Response.Write("删除成功");可结果是:
    <?xml version="1.0" encoding="gb2312"?>
    <NewsSubject>
      <subject>
       </subject>
      <subject>
        <lm_id>2</lm_id>
        <lm_name>春运</lm_name>
      </subject>
      <subject>
        <lm_id>3</lm_id>
    <l_name>栏目3</l_name>
      </subject>
    </NewsSubject>我想把空的
    <subject>
       </subject>
    也删除。请问怎么做?
      

  6.   

    我用2002pine的
    XmlNode delNode = xmldoc.SelectSingleNode("NewsSubject/subject/[lm_id=3]");
    xmldoc.DocumentElement.RemoveChild(delNode);
    还是不行啊。
    报错“
    传递给此方法的表达式应产生 NodeSet。 
      

  7.   

    sorry:
    XmlNode delNode = xmldoc.SelectSingleNode("NewsSubject/subject/[lm_id=3]");
    -->
    XmlNode delNode = xmldoc.SelectSingleNode("NewsSubject/subject[lm_id=3]");
      

  8.   

    http://expert.csdn.net/Expert/TopicView1.asp?id=2871858
    2002pine(我学习,我存在)来接分