title: How to access XML element array under an XML element?
body: <p>I have an XML file which I read and deserialize into an object "newProject" using XMLSerializer. I need to modify certain parts of the object and serialize back into an XML file. </p>
  
  <p>I can do this for the most part, but cannot figure out how to change values if there is an array of XML element under an XML element. </p>
  
  <p>For example I have the following class:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class addDataData {
  
      private System.Xml.XmlElement anyField;
  
      private string nameField;
  
      private addDataDataHandleUnknown handleUnknownField;
  
      /// &lt;remarks/&gt;
      [System.Xml.Serialization.XmlAnyElementAttribute()]
      public System.Xml.XmlElement Any {
          get {
              return this.anyField;
          }
          set {
              this.anyField = value;
          }
      }
  }
  </code></pre>
  
  <p>I'm trying to write values to the xml array elements under the "Any" element. </p>
  
  <p>I've tried:</p>
  
  <pre><code>newProject.addData[i].Any[0] = fbFolderList[0];
  </code></pre>
  
  <p>I get Error "Argument 1: Cannot conver from int to string" because VS wants you to type in the XML string name here.</p>
  
  <p>I also tried:</p>
  
  <pre><code>newProject.addData[i].Any = fbFolderList.ToArray(); 
  </code></pre>
  
  <p>Where the fbFolderList contains XML elements that I modified.
  This also give me error</p>
  
  <pre><code>Cannot implicityly convert System.xml.xmlElement[] to system.xml.xmlElement
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Vd6FL.png" rel="nofollow noreferrer">VS wants me to insert a XmlNode name in the [] to get the xml element instead of referencing the array element number...</a></p>
  
  <p>Here is a screen shot of the object structure.</p>
  
  <p>When I try using a <code>foreach</code> loop I can access the array values under "Any" element, but as you know, you cannot write values into the foreach iteration variable.</p>
  
  <pre class="lang-cs prettyprint-override"><code>private void ReadAddData(addDataData[] data)
  {
      foreach (addDataData d in data)
      {
          foreach(XmlElement folder in d.Any)
          {
                fbFolderList.Add(folder)
          }
      }   
  }
  </code></pre>
  
  <p>Is there a way to tell the compiler or the program that I want to access the array values and not to get the xml element name?</p>
  
  <p>Thank you I appreciate any help you can give me.</p>
  
  <p>Sorry I'm new and not sure how I can attach an Xml file to this post. The Xml is huge, but I've attaches a screenshot of the xml in watch window
  <a href="https://i.stack.imgur.com/nF03W.png" rel="nofollow noreferrer">xml screenshot</a></p>
  
  <p>Here is the simplified form of my xml document.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201"&gt;
    &lt;fileHeader companyName="x" companyURL="xx"/&gt;
    &lt;instances&gt;
      &lt;configurations&gt;&lt;/configurations&gt;
    &lt;/instances&gt;
    &lt;addData&gt;
      &lt;data name="http:/xml/projectPlcType" handleUnknown="implementation"&gt;
        &lt;projectPlcType name="R08" /&gt;
      &lt;/data&gt;
      &lt;data name="http:/xml/projectFolders" handleUnknown="implementation"&gt;
        &lt;projectFolders&gt;
          &lt;folder name="AVM" type="functionBlock" functionBlockType="macro" modificationDateTime="2018-11-08T12:08:01-06:00" /&gt;
          &lt;folder name="PLCOpenServo" type="functionBlock" functionBlockType="macro" modificationDateTime="2018-11-12T10:09:16-06:00" /&gt;
        &lt;/projectFolders&gt;
      &lt;/data&gt;
    &lt;/addData&gt;
  &lt;/project&gt;
  </code></pre>