为什么要删除,删除就不是合格的XML文档了.删除方法,try:XmlDocument doc = new XmlDocument();
doc.Load(@"e:\1.xml");
doc.RemoveChild(doc.FirstChild);
doc.Save(@"e:\1.xml");

解决方案 »

  1.   

    XmlDocument doc = new XmlDocument();
                doc.Load("e:\\1.xml");
                doc.RemoveChild(doc.FirstChild);
                doc.Save("e:\\1.xml");
      

  2.   

    恩。谢谢!那么我要再第一行加上(<?xml version="1.0" encoding="gb2312"?>)这行呢?文件有其他内容,类似这样
    <doc>
        <assembly>
            <name>haha</name>
        </assembly>
    </doc>
      

  3.   

    XmlDocument doc = new XmlDocument();
    doc.Load(@"e:\1.xml");
    XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "gb2312", "no");
                doc.InsertBefore(dec, doc.FirstChild);
    doc.Save(@"e:\1.xml");
      

  4.   

    是这样的有一个xml格式的文件,但是没有头,这样的话处理时因为有汉字所以报错,加上一个头(带encoding)的就好了。所以需要后加一个头,各位帮帮忙看一下。!!!
      

  5.   

    加头:XmlDocument doc = new XmlDocument();
    doc.Load(@"e:\1.xml");
    XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "gb2312", "no");
    doc.InsertBefore(dec, doc.FirstChild);
    doc.Save(@"e:\1.xml");