Bonjour,
je travaille sous visual c++ (.net)
je veux faire une petite fonction qui me parcours le fichier xml et supprime un child donné
le probleme c'est que il me dit qu'il le trouve pas le child ou child inexistent, alors que je suis sur qu'il la , et pour etre completement sur je l ajoute avec appendchild et juste apres j utilise removechild il me dit inexistent
voici mon code : (je crois que le probleme viens de la creation de elem21)
XmlDocument^doc1 = gcnew XmlDocument();
doc1->Load("c:\\test30.xml");
XmlNode^ elem21 = doc1->CreateNode(XmlNodeType::Element, "file", nullptr);
elem21->InnerText = "file111";
for each (XmlNode^xn in doc1->ChildNodes[0]->ChildNodes)
{
if((xn->Attributes["id"]->Value->ToString()=="1"))
{
for each (XmlNode ^xcn in xn->ChildNodes)
{
if(xcn->Name->ToString()=="roles")
{
for each (XmlNode ^xcn2 in xcn->ChildNodes)
{
if((xcn2->Attributes["id"]->Value->ToString()=="1"))
{
for each (XmlNode ^xxx in xcn2->ChildNodes)
{
if((xxx->Name->ToString()=="users"))
{
System::Windows::Forms::MessageBox::Show(xxx->Name->ToString());
for each (XmlNode ^xxxm in xxx->ChildNodes)
{
if((xxxm->Name->ToString()=="user"))
{
if(xxxm->Attributes["login"]->Value->ToString()=="login11")
{
for each (XmlNode ^xxxmm in xxxm->ChildNodes){
System::Windows::Forms::MessageBox::Show("xxxmm\n"+xxxmm->Name->ToString()+"\n");
xxxmm->RemoveChild(elem21);
}
}
}
}
}
}
}
}
}
}
}
}
System::Windows::Forms::MessageBox::Show("ca marche avant save");
doc1->Save("c:\\test30.xml");
System::Windows::Forms::MessageBox::Show("ca marche");
est ce que quelqu'un peut m aider
merci
juste une remarque : quand je fais apend puis remove dans la meme methode ca marche ?!
xxxmm->ApendChild(elem21);
xxxmm->RemoveChild(elem21);