我试图用SelectSingleNode
. 文件的结构是
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ProjectExtensions>
<Borland.Personality>Delphi.Personality</Borland.Personality>
<Borland.ProjectType>VCLApplication</Borland.ProjectType>
<BorlandProject>
<BorlandProject>
<Delphi.Personality>
<Parameters>
...
</Parameters>
<VersionInfo>
<VersionInfo Name="IncludeVerInfo">True</VersionInfo>
<VersionInfo Name="AutoIncBuild">False</VersionInfo>
<VersionInfo Name="MajorVer">4</VersionInfo>
<VersionInfo Name="MinorVer">1</VersionInfo>
<VersionInfo Name="Release">3</VersionInfo>
<VersionInfo Name="Build">559</VersionInfo>
<VersionInfo Name="Debug">False</VersionInfo>
<VersionInfo Name="PreRelease">False</VersionInfo>
<VersionInfo Name="Special">False</VersionInfo>
<VersionInfo Name="Private">False</VersionInfo>
<VersionInfo Name="DLL">False</VersionInfo>
<VersionInfo Name="Locale">1049</VersionInfo>
<VersionInfo Name="CodePage">1251</VersionInfo>
</VersionInfo>
...
...
...
我在 VS C# 上的代码是
using System.Xml;
namespace xmledit
{
class Program
{
private static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("arm.xml");
var node = doc.SelectSingleNode("//VersionInfo[@Name='Build']");
if (node != null)
node.InnerText = "123";
doc.Save("temp.xml");
}
}
}
所以,我试图用 修改标签VersionInfo
,Name="Build"
但SelectSingleNode
返回NULL
。我做错了什么?