title: How can i programatically read in the both AcroFields and XFA fields for filling?
body: <p>I am writing a C# application that will need to read in both XFA and AcroField templates. Due to the size of the company and the number of existing PDF documents that may be hooked up to the application, picking one and going with it is out of the question. </p>
  
  <p>I am currently using iTextSharp to read in the AcroFields, but it is not actually saving the changes. I made the AcroFields using the trial version of Acrobat Pro. </p>
  
  <p>EDIT: (I deleted a lot of the origional post)</p>
  
  <p>I have a workaround somewhat working, but I would rather not do a Deapth First Search on the XML. I also do not have it figuring out anything other than text fields yet. </p>
  
  <pre><code>public List&lt;String&gt; getKeys(AcroFields af)
  {
      XfaForm xfa = af.Xfa;
      List&lt;String&gt; Keys = new List&lt;string&gt;();
      foreach (var field in af.Fields)
      {
          Keys.Add(field.Key);
      }
      if (xfa.XfaPresent)
      {
          System.Xml.XmlNode n = xfa.DatasetsNode.FirstChild;
          if (n == null) return Keys;
  
          // drill down in to the children
          while (n.FirstChild != null) { n = n.FirstChild;  }  
  
          // if the node is filled in data, grab the parent
          if ((n.Name.ToCharArray(0, 1))[0] == '#') n = n.ParentNode; 
          while ((n = n.NextSibling) != null)
          {
              Keys.Add(n.Name);
          }
      }
      return Keys;
  }
  </code></pre>