xpathlinq-to-xmlxattribute

Problem Reading XElement Attribute


Anyone knows why this xpath expression "catzero/@id" is not working on this xml

document = XDocument.Load("file.xml");
var product = document.XPathSelectElements("//product", nameSpaceResolver).First();
var category = ((IEnumerable) product.XPathEvaluate("catzero/@id")).Cast<XAttribute>().first().value; //catezero/@id is null

Solution

  • Are you entering Xpath expression into Xelement()?
    To use Xpath you should try http://msdn.microsoft.com/en-us/library/system.web.ui.templatecontrol.xpathselect.aspx