SelectSingleNode在dnx core 5.0中出现编译错误
我使用SelectSingleNode方法遇到此错误: DNX Core 5.0错误CS1061:“XmlDocument”不包含“SelectSingleNode”的定义,并且找不到接受“XmlDocument”类型的第一个参数的扩展方法“SelectSingleNode”(是否缺少using指令或程序集引用?)SelectSingleNode在dnx core 5.0中出现编译错误,selectsinglenode,dnx50,Selectsinglenode,Dnx50,我使用SelectSingleNode方法遇到此错误: DNX Core 5.0错误CS1061:“XmlDocument”不包含“SelectSingleNode”的定义,并且找不到接受“XmlDocument”类型的第一个参数的扩展方法“SelectSingleNode”(是否缺少using指令或程序集引用?) 现在还不支持吗?我的选择是什么?我也有这个问题。为了解决这个问题,我使用XDocument,到目前为止还不错 例如: 不要忘记将“System.Xml.XDocument”包含在项
现在还不支持吗?我的选择是什么?我也有这个问题。为了解决这个问题,我使用XDocument,到目前为止还不错 例如:
不要忘记将
“System.Xml.XDocument”
包含在项目.json中 您需要使用XDocument
const string xml = "<Misc><E_Mail>email@domain.xyz</E_Mail><Fax_Number>111-222-3333</Fax_Number></Misc>";
const string tagName = "E_Mail";
XDocument xDocument = XDocument.Parse(xml);
XElement xElement = xDocument.Descendants(tagName).FirstOrDefault();
if (xElement == null)
{
Console.WriteLine($"There is no tag with the given name '{tagName}'.");
}
else
{
Console.WriteLine(xElement.Value);
}
conststringxml=”email@domain.xyz111-222-3333";
常量字符串标记名=“电子邮件”;
XDocument XDocument=XDocument.Parse(xml);
XElement XElement=xDocument.subjects(标记名).FirstOrDefault();
if(xElement==null)
{
WriteLine($“没有具有给定名称“{tagName}”的标记”);
}
其他的
{
Console.WriteLine(xElement.Value);
}
在.Net Core 1.0和.Net Standard 1.3中,SelectSingleNode是一种扩展方法
添加引用以使其再次可用:
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />