XDocument.Descendants() not returning any elements

喜欢而已 提交于 2019-11-27 15:02:11

The string parameter passed to Descendents is actually implicitly converted to an XName object. An XName represents a fully qualified element name.

The document defines a namespace "i", therefore I believe you need to use the fully qualified name to access Employee. ie. i:Employee, where the prefix "i: actually resolves to the full namespace string.

Have you tried something like:

XName qualifiedName = XName.Get("Employee", "http://www.w3.org/2001/XMLSchema-instance");

var employees = from e in xml.Descendants(qualifiedName)

...

You are not including the namespace from the parent element:

XNameSpace ns = "http://schemas.datacontract.org/2004/07/Employees.Entities";
foreach (XElement element in xdoc.Descendants(ns + "Employee")
{
    ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!