mercredi 25 février 2015

C# application will not display last Attribute Value in XML Document

A C# project I am working on will not display/insert the last value within an XML tag. For Example my application iterates through this tag and will get 1, 2 3 but not 4. It does that with every iteration.



<purpose>
<intendedUse id="1"/>
<intendedUse id="2"/>
<intendedUse id="3"/>
<intendedUse id="4"/>
</purpose>


I believe it has something to do with the int num declaration.



for (i = 0; i < xmlnode.Count - 1; i++ )
{
str = xmlnode[i].Attributes[0].Value;
int num = Int32.Parse(str) - 1;
for ( var count = 0; count < xmlnode[num].FirstChild.NextSibling.ChildNodes.Count - 1; count++)
{
str2 = xmlnode[num].FirstChild.NextSibling.ChildNodes[count].Attributes[0].Value;
MessageBox.Show(str2);
}

//SQLiteCommand cmd = new SQLiteCommand(connection);
//cmd.CommandText = "INSERT INTO languagePurpose (purposeID, languageID) VALUES ('" + str2 + "', '" + str + "')";
//SQLiteDataReader dr = cmd.ExecuteReader();
// MessageBox.Show(str);
}

Aucun commentaire:

Enregistrer un commentaire