I am getting this error with SelectSingleNode method: DNX Core 5.0 error CS1061: 'XmlDocument' does not contain a definition for 'SelectSingleNode' and no extension method 'SelectSingleNode' accepting a first argument of type 'XmlDocument' could be found (are you missing a using directive or an assembly reference?)
Is it not supported yet? What are my alternatives?
In .Net Core 1.0 and .Net Standard 1.3 SelectSingleNode is an extenstion method
https://github.com/dotnet/corefx/issues/17349
Add a reference to make it available again:
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
You need to use 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);
}
I have this problem too. To solve that, I'm using XDocument and so far so good.
Example:
XDocument xdoc = XDocument.Parse(xmlText);
var singleNode = xdoc.Element("someAttr");
var listOfNodes = singleNode.Elements("someAttrInnerText");
foreach (XElement e in listOfNodes)
{
string someAttr = e.Attribute("code").Value;
string someAttrInnerText = e.Value;
}
Don't forget to include "System.Xml.XDocument"
inside your project.json.
来源:https://stackoverflow.com/questions/35089399/selectsinglenode-is-giving-compilation-error-in-dnx-core-5-0