XDocument does not return the expected node

I try to work with the XDocument in C# but have some problems to receive the desired elements. Here is my sample xml

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
  <f href="@{pdffile}"/>
  <ids modified="BF43C70442ECB74FA49833BBA44D4679" original="B4870CC046121A41B7D8F0838C87256D"/>
  <fields>
    <field name="FormInstanceID"><value>@{instanceid}</value></field>
    <field name="meta_7"><value>@{meta_7}</value></field>
    <field name="meta_6"><value>@{meta_6}</value></field>
    <field name="meta_8"><value>@{meta_8}</value></field>
    <field name="meta_3"><value>@{meta_3}</value></field>
    <field name="meta_2"><value>@{meta_2}</value></field>
    <field name="meta_5"><value>@{meta_5}</value></field>
    <field name="meta_4"><value>@{meta_4}</value></field>
    <field name="meta_1"><value>@{meta_1}</value></field>
    <field name="tag_5"><value>@{tag_5}</value></field>
    <field name="tag_1"><value>@{tag_1}</value></field>
    <field name="tag_2"><value>@{tag_2}</value></field>
    <field name="tag_3"><value>@{tag_3}</value></field>
    <field name="TAGS"><value>@{TAGS}</value></field>
    <field name="tag_4"><value>@{tag_4}</value></field>
    <field name="qr"><value>@{qr}</value></field>
    <field name="metadata"><value>@{metadata}</value></field>
    <field name="pdx.dynform.email"><value>@{pdx.dynform.email}</value></field>
  </fields>
</xfdf>

Assuming the given XML I want to extract with XDocument the field values. Currently I do no receive any entry by using this approach

XDocument xfdfData = XDocument.Load(xfdf);
var result = xfdfData.Descendants("fields");

The file is sucessfully loaded in the xfdfData object but the Descendants("fields") does find any nodes.

Jon Skeet
people
quotationmark

You don't have a fields element which isn't in a namespace, which is what you're asking for. Due to this in the root element:

xmlns="http://ns.adobe.com/xfdf/"

... the default namespace URI for the descendant nodes is http://ns.adobe.com/xfdf/. So you want:

XNamespace ns = "http://ns.adobe.com/xfdf/";
XDocument doc= XDocument.Load(xfdf);
var result = doc.Descendants(ns + "fields");

Or to find the field elements themselves:

XNamespace ns = "http://ns.adobe.com/xfdf/";
XDocument doc= XDocument.Load(xfdf);
var fields = doc.Descendants(ns + "field");

people

See more on this question at Stackoverflow