I trying to modify an XML file with SelectSingleNode
.
The structure of file is
<?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>
...
...
...
My code on VS C# is
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");
}
}
}
So, i trying to modify Tag VersionInfo
with Name="Build"
, but SelectSingleNode
returns NULL
.
What I doing wrong?
Your xml document has an default namespace xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
therefore (I assume) you need to use a XmlNamespaceManager.