XML éviter de réécrire le fichier
Bonsoir à tous,
Voici un petit soucis qui m'embête un peu.
J'ai un fichier XML:
Code:
1 2 3 4 5
| <Connect>
<Id1>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA</Id1>
<Mdp1>ZUuHfFNO9ZwAAAAAOgAAAAAIAACAAAADn8m7UvxAcUB462XKBr</Mdp1>
//Je voudrais écrire à partir d'ici
<Connect/> |
Donc mon problème est d"écrire après la balise </Mdp1>. Auparavant je supprimais le fichiers et le recréait avec StreamWriter m'évitant de bloqué sur ce cas. Mais là j'aurais besoin que ca fonctionne :P
J'utilise XmlTextWriter, j'ai cru comprendre que c'était possible avec...
Mais pour l'instant c'est le vide avec ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| byte[] bytesId = Encoding.UTF8.GetBytes(AjoutIdMulti.Text); //String en byte
byte[] protectedId = ProtectedData.Protect(bytesId, null, DataProtectionScope.CurrentUser); //Cryptage
byte[] bytesMdp = Encoding.UTF8.GetBytes(AjoutMdpMulti.Text);
byte[] protectedMdp = ProtectedData.Protect(bytesMdp, null, DataProtectionScope.CurrentUser);
FileStream f = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
XmlTextWriter xmlw = new XmlTextWriter(f, System.Text.Encoding.UTF8);
xmlw.WriteStartDocument();
xmlw.WriteStartElement("Connect");
if (identifiant1 != "vide")
{
xmlw.WriteStartElement("Id1");
xmlw.WriteEndElement();
xmlw.WriteStartElement("Mdp1");
xmlw.WriteEndElement();
if (identifiant2 != "vide")
{
xmlw.WriteStartElement("Id2");
xmlw.WriteEndElement();
xmlw.WriteStartElement("Mdp2");
xmlw.WriteEndElement();
}
else
{
xmlw.WriteStartElement("Id2");
xmlw.WriteString(Convert.ToBase64String(protectedId));
xmlw.WriteEndElement();
xmlw.WriteStartElement("Mdp2");
xmlw.WriteString(Convert.ToBase64String(protectedMdp));
xmlw.WriteEndElement();
}
}
xmlw.WriteEndElement();
xmlw.Flush();
xmlw.Close();
f.Close(); |
Je sais ce n'est pas très beau à voir :roll:, mais je découvre XmlTextWriter et comme l'indique Writer ce n'est pas la bonne voie pour sauter les balise Id1 et Mdp1.
Comment je pourrais faire pour ne pas supprimer les value de Id1 Mdp1??
Si quelqu'un a un idée??
Merci.