c# - How to retrieve descendants using Linq -
i have xml in i'm looping through every node
, in want retrieve xhtml
elements , tried
foreach (xelement element in xdoc.descendants(namespace)) { var result = element.descendants(namespace + "xhtml") }
but enumeration returning empty
data :
<namespace xmlns="http://www.find.org/schemas/"> <date>2015</date> <xhtml:link xmlns:xhtml="xhtml:link" rel="alternate" /> <xhtml:link xmlns:xhtml="xhtml:link" rel="alternate" /> <xhtml:link xmlns:xhtml="xhtml:link" rel="alternate" /> </namespace>
your link elements in own namespace, called xhtml
in namespace xhtml:link
. need use select elements.
// namespace of yout document var ns = (xnamespace) "http://www.find.org/schemas"; // namespace of link elements var nsxhtml = (xnamespace) "xhtml:link"; var result = xdoc.root.elements(nsxhtml+ "link"); result.dump();
in xml document should on lookout xmlns:
constructs , can @ top or defined on element. using no or wrong namespace not find elements.
Comments
Post a Comment