C# 需要使用正则表达式从xml文件中获取数字

C# 需要使用正则表达式从xml文件中获取数字,c#,C#,我有一个场景,其中我有一个xml内容,我需要从该文件中获取版本号。下面是一个例子 <testing Version1 = "1.1" Version2 = "1.3"> <name> Example </Name> <Description>sample description</Description> </testing> 实例 样本描述 我需要版本2的值,即1.3。是否可以使用正则表达式获取它 提前感谢,您无需正

我有一个场景,其中我有一个xml内容,我需要从该文件中获取版本号。下面是一个例子

<testing Version1 = "1.1" Version2 = "1.3">
<name> Example </Name>
<Description>sample description</Description>
</testing>

实例
样本描述
我需要版本2的值,即1.3。是否可以使用正则表达式获取它


提前感谢,

您无需正则表达式即可完成此操作-示例:

var xml = @"<testing Version1 = ""1.1"" Version2 = ""1.3"">
<Name> Example </Name>
<Description>sample description</Description>
</testing>";

string version2 = XElement.Parse(xml).Attribute("Version2").Value;
var xml=@”
实例
样本描述
";
字符串version2=XElement.Parse(xml).Attribute(“version2”).Value;

为什么不使用
XDocument
?请参阅: