Categories
Development

XDocument xml parsed but fails to save attributes. Xml.Linq

I am looping over the controls and setting the textbox values in the xml like so:

using System.Xml.Linq;

/* code */

XDocument _xml = XDocument.Load(_DialogOpen);

foreach (Control t in tableLayoutPanel.Controls)
{
    if (t is TextBox)
    {
        //setting the value
        _xml.Root.SetAttributeValue("isPreview", t.Text);
        //log
        textBox.AppendText("n=" + t.Name + " t=" + t.Text + Environment.NewLine);           
    }
}

_xml.Save(_DialogOpen);

My problem is that the _xml.Save(_DialogOpen); does save but none of the attributes are changed and there is no exception. If anyone has any suggestions it will be greatly appreciated.

xml example:

<?xml version="1.0" encoding="utf-8"?>
<config id="1">
  <parmVer __id="0" version="V1234" />
    <RecordSetChNo __id="0" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="1" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="2" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="3" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="4" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="5" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="6" isPreview="1" AIVolume="15" />
    <RecordSetChNo __id="7" isPreview="1" AIVolume="15" />
</config>

Leave a Reply

Your email address will not be published. Required fields are marked *