Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言编辑XML文件_C#_Xml_System.xml - Fatal编程技术网

C# 用C语言编辑XML文件

C# 用C语言编辑XML文件,c#,xml,system.xml,C#,Xml,System.xml,因此,这是我第一次使用XML文档,我需要一些帮助。 我的XML文件中有此段: <configuration> <appSettings> <add key="PhoneVersion" value="36.999.1" /> <add key="TabletVersion" value="36.999.1" /> <add key="DesktopVersion" value="36.999.1" />

因此,这是我第一次使用XML文档,我需要一些帮助。 我的XML文件中有此段:

<configuration>
  <appSettings>
    <add key="PhoneVersion" value="36.999.1" />
    <add key="TabletVersion" value="36.999.1" />
    <add key="DesktopVersion" value="36.999.1" />
  </appSettings>
</configuration>
我试图读取每行的值,并将最后一个数字增加+1

我能够阅读整个文件,但我只想阅读的行说明

任何帮助???

使用XElement加载xml文件。然后,可以使用方法子体迭代节点的子体节点

最后,您可以使用Attribute读取节点的属性。

尝试使用Xml Linq:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication51
{

    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";

        static void Main(string[] args)
        {
            XDocument doc = XDocument.Load(FILENAME);

            foreach (XElement add in doc.Descendants("add"))
            {
                string[] values = add.Attribute("value").Value.Split(new char[] {'.'});
                values[values.Length - 1] = (int.Parse(values[values.Length - 1]) + 1).ToString();
                add.SetAttributeValue("value", string.Join(".", values));
            }

        }
    }


}

你能显示一些代码吗?我可以读取整个文件,但是我只想读取所述的行-但是XDoxument.LoadFILENAME将读取整个文件。Windows不允许你修改文件的一部分。您必须读取整个文件,然后将其写回。