Auto Increment ID in XML File
<p>Could someone help me do this?
I wish he auto-increment, but he does not.
Could you help me do this?</p>

<p>My code is:</p>

<pre><code>    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(Server.MapPath(@"Participantes.xml"));


    XmlElement newElement = xmlDoc.CreateElement("ID" **/* this is need auto-increment */**);
    XmlElement xmlNome = xmlDoc.CreateElement("Nome");
    XmlElement xmlClass = xmlDoc.CreateElement("Classe");
    XmlElement xmlFaccao = xmlDoc.CreateElement("Facção");
    XmlElement xmlLevel = xmlDoc.CreateElement("Level");


    xmlNome.InnerText = this.TextBox_I1.Text.Trim();
    xmlClass.InnerText = this.Class_I1.SelectedItem.Text.Trim();
    xmlFaccao.InnerText = this.Faccao.SelectedItem.Text.Trim();
    xmlLevel.InnerText = this.TextBox_lvl.Text.Trim();

    newElement.AppendChild(xmlNome);
    newElement.AppendChild(xmlClass);
    newElement.AppendChild(xmlFaccao);
    newElement.AppendChild(xmlLevel);

    xmlDoc.DocumentElement.AppendChild(newElement);
    xmlDoc.Save(Server.MapPath(@"Participantes.xml"));
</code></pre>

<p>Anyone can help-me?
Anyone know how this?</p>

<p><em><strong></em>__<em>_</em>__<em>_</em>__<em>_</em>_</strong> EDIT 09/05/2012 <strong><em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em></strong></p>

<p>Solution:</p>

<pre><code>        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath(@"Participantes.xml"));


        var x = xmlDoc.GetElementsByTagName("ID");
        int Max = 0;
        foreach (XmlElement item in x)
        {
            int ultimoID = Convert.ToInt32(item.GetAttribute("value"));
            if (ultimoID &gt; Max)
            {
                Max = ultimoID;
            }
        }
        Max++;


        XmlElement newElement = xmlDoc.CreateElement("ID");
        newElement.SetAttribute("value", Max.ToString());
        XmlElement xmlNome = xmlDoc.CreateElement("Nome");
        XmlElement xmlClass = xmlDoc.CreateElement("Classe");
        XmlElement xmlFaccao = xmlDoc.CreateElement("Facção");
        XmlElement xmlLevel = xmlDoc.CreateElement("Level");


        xmlNome.InnerText = this.TextBox_I1.Text.Trim();
        xmlClass.InnerText = this.Class_I1.SelectedItem.Text.Trim();
        xmlFaccao.InnerText = this.Faccao.SelectedItem.Text.Trim();
        xmlLevel.InnerText = this.TextBox_lvl.Text.Trim();

        newElement.AppendChild(xmlNome);
        newElement.AppendChild(xmlClass);
        newElement.AppendChild(xmlFaccao);
        newElement.AppendChild(xmlLevel);

        xmlDoc.DocumentElement.AppendChild(newElement);
        xmlDoc.Save(Server.MapPath(@"Participantes.xml"));
</code></pre>

<p>Use Attributes...
Because we have to follow the standard XML.
Select ID to set value with GetElementsByTagName!
Use foreach to verify Attribute "value" and insert +1 using SetAttribute</p>
