我想修改这个xml文件,使了半天都不行,怎么弄呢?

解决方案 »

  1.   

    private void CZXml(object o)
            {
                if (File.Exists(@"c:\1.xml"))
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(@"c:\1.xml");                XmlNode nCount = xmlDoc.FirstChild.SelectSingleNode("Count");
                    int n = Convert.ToInt32( nCount.InnerText);
                    nCount.InnerText = (n + 1).ToString();                //xmlDoc.Save(@"c:\1.xml");
                }
                else
                {
                    XmlDocument xmlDoc = new XmlDocument();                XmlNode root = xmlDoc.CreateElement("root");
                    XmlNode nCount = xmlDoc.CreateElement("Count");
                    nCount.InnerText = "0";                root.AppendChild(nCount);
                    xmlDoc.AppendChild(root);                xmlDoc.Save(@"c:\1.xml");
                }
            }
      

  2.   

    你的xml文件内容是什么,是否为xml标准格式。
      

  3.   

    XmlDocument xdoc= new XmlDocument();
    StreamReader sr = new StreamReader(@"d:\test.xml",Encoding.Default); 
    xdoc.Load(sr);
    sr.Close();
      

  4.   

    using System;
    using System.IO;
    using System.Text;
    using System.Diagnostics;
    using System.Threading;
    using System.Collections;
    using System.Data;
    using System.Xml;
    using System.Management;
    using System.Net;
    namespace Zhzuo
    {
    class ZZConsole
    {
    [STAThread]
    static void Main(string[] args)
    {
    string strXml="<?xml version=\"1.0\"?>"
    +"<Data>"
    +"<Head>"
    +"<Nodeid>1111</Nodeid>"
    +"<Subid>2222</Subid>"
    +"<Version>2004</Version>"
    +"<Date>20040302</Date>"
    +"<Time>101500</Time>"
    +"</Head>"
    +"<Body>"
    +"<Code>01</Code>"
    +"<Name>深圳</Name>"
    +"<IdType>0</IdType>"
    +"<Idno>110258740824082</Idno>"
    +"</Body>"
    +"</Data>";
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXml);
    string vv;

    XmlNodeList myNodes = doc.GetElementsByTagName("Version");
    vv = myNodes[0].InnerText;
    //修改
    myNodes[0].InnerText = "123455";
    Console.WriteLine(vv);
    myNodes = doc.SelectNodes("//Version");
    vv = myNodes[0].InnerText;
    Console.WriteLine(vv);
    //修改
    myNodes[0].InnerText = "67890";
    doc.Save("d:\\text.xml");
    Console.ReadLine();
    }

    }

    }
      

  5.   

    把XML文件贴出来
    然后说一下想要怎去操作这个XML文件