IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

suppression noeud xml from datagridview c#


Sujet :

C#

  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut suppression noeud xml from datagridview c#
    bonjour

    j'ai une base de donnée xml qui est afficher dans un datagridview en c#
    je veux lorsque l'utilisateur selectionne une ligne datagridview (ligne datagridview correspond a un noeud xml) et appuie sur un bouton supprimer alors cette ligne sera supprimer de la base de donnée
    j'ai affecter ce code mais ça marche pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     private void optionsToolStripMenuItem1_Click(object sender, EventArgs e)
            {
               String Io;
                try{
                DialogResult dr;
                dr=MessageBox.Show("Voulez vous vraiment supprimer cet element","Attention",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
                if (dr == DialogResult.No)
                {
                    return;
                }
                else
                {
                    Io = (dataGridView1.SelectedRows[0].Cells[0].ToString());
                    XmlDocument Doc = new XmlDocument();
                    Doc.Load(Application.StartupPath + "\\Videos.xml");
                    XmlNode Node = Doc.SelectSingleNode("copie" + Io);
                    if (Node != null)
                    {
                        Doc.DocumentElement.RemoveChild(Node);
                        MessageBox.Show("suppression réeussite", "suppression", MessageBoxButtons.OK);
                    }
                    else { }
                    Doc.Save(Application.StartupPath + "\\Videos.xml");
                }
                }
                     catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }
    }
    il m'affiche un message: copie datagridviewTextboxCell{columnIndex=0,RowIndex=22} a un jeton non valide
    aussi j'ai fait un autre code mais ça marche pas aussi:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.GetElementsByTagName("video");
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
                        if (objInnerNode.InnerText == dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.DocumentElement.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }
    S'il vous plais j'attend votre aide
    Merci beaucoup

  2. #2
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    et ta quoi comme exception?

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    et ta quoi comme exception?
    quoi ? j'ai pas compris ton question

  4. #4
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    est que tu a une exception ou bien le node n'est supprimer de ton fichier ?

    et comment ta rempi ton datagridview est ce que avec datasoure ou bien??

  5. #5
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    est que tu a une exception ou bien le node n'est supprimer de ton fichier ?

    et comment ta rempi ton datagridview est ce que avec datasoure ou bien??
    mon datagridview est rempli via une base de donnée xml
    et lopération de suppression n'est pas effectuée

  6. #6
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    pourquoi copie+IO

    XmlNode Node = Doc.SelectSingleNode("copie" + Io);

  7. #7
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    pourquoi copie+IO
    copie just message pour l'affichage
    io c'estdataGridView1.SelectedRows[0].Cells[0].ToString() : le noeud selectionnée ??
    c 'est pas correct??
    est ce que tu peut m'aider a améliorer ce code ?
    Merci bien

  8. #8
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    tu va me donner le XML ainsi que le code que ta utiliser pour remplir ton datagrid

  9. #9
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    tu va me donner le XML ainsi que le code que ta utiliser pour remplir ton datagrid
    voila mon xml:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <Videos>
      <Video>
        <FICHIER>C:\Users\benrhaie\Desktop\La classification des données est une sorte de fiche d.docx</FICHIER>
        <TITRE>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=4620422</TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCÉES>14:52:58</HEUREDERNIERACCÉES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE> Dans un</COPIE>
      </Video>
      <Video>
        <FICHIER>C:\Users\benrhaie\Desktop\La classification des données est une sorte de fiche d.docx</FICHIER>
        <TITRE>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=4620422</TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCÉES>14:52:58</HEUREDERNIERACCÉES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE>/14/PDF/p178.pdf</COPIE>
      </Video>
     <Video>
        <FICHIER>d.docx</FICHIER>
        <TITRE>
        </TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCÉES>2012-10-08</HEUREDERNIERACCÉES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE>rrrrrrrrrrrrrrrrrrrrrrrrrrr</COPIE>
        <aaaa>aaaaaaaaaaaa </aaaa>
        <Category>elemnt ajouter pour ce texte</Category>
      </Video>
    </videos>
    Le remplissage via la base dans un datagridview c'est:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
     try
                {
                    XmlReader xmlFile;
                    xmlFile = XmlReader.Create("Videos.xml", new XmlReaderSettings());
                    DataSet ds = new DataSet();
                    ds.ReadXml(xmlFile);
                    dataGridView1.DataSource = ds.Tables[0];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
    MErci

  10. #10
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    tu peux faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.DocumentElement.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }

    et tu fait appel a nouveau a ton code de remplir datagridview

  11. #11
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    tu peux faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.DocumentElement.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }

    et tu fait appel a nouveau a ton code de remplir datagridview
    Lorsque je selectionne une ligne et j'appuie sur le bouton de suppression il m'affiche un msg: La reférence d'objet n'est pas définie à une instance d'objet
    ???????

  12. #12
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
    if(objInnerNode.Value !=null)
    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.DocumentElement.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
    }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }

  13. #13
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
    if(objInnerNode.Value !=null)
    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.DocumentElement.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
    }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }
    en fait il m'affiche un erreur dans cette ligne:
    if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
    alors j'ai changé Tostring() par ToString()
    et il m'affiche la meme msg: La réference d'objet n'est pas définie à une instance d'objet
    c'est quoi le problème ?

  14. #14
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
    if(objInnerNode.Value !=null)
    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
    }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }
    désolé je travail sur mon pc personnel donc pas de visuel studio pour tester avant

  15. #15
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
    if(objInnerNode.Value !=null)
    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
    }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }
    désolé je travail sur mon pc personnel donc pas de visuel studio pour tester avant
    Merci bien azstar pour ton aide mais toujour il m'affiche la meme msg: La réference d'objet n'est pas définie à une instance d'objet !!
    j'ai pas compris où le problème ?

    moi je change toujour cette ligne : objInnerNode.Value.Tostring() pag objInnerNode.Value.ToString() il faut S majuscule

    j'attend ton aide merci bien

  16. #16
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
     
    string strFilename = "Videos.xml";
               bool blnFlag = false;
               XmlDocument objXMLDoc = new XmlDocument();
               objXMLDoc.Load(Application.StartupPath + "/videos.xml");
            //XmlDocument objXMLDoc = ReadXML();
     
            XmlNodeList lstMovies = objXMLDoc.ChildNodes;
            try
            {
     
                foreach (XmlNode objNode in lstMovies)
                {
                    //XmlNodeList objNodeList = objNode.ChildNodes; 
                    XmlNode objNodeList = objNode.ChildNodes[1];
     
                    foreach (XmlNode objInnerNode in objNodeList)
                    {
    if(objInnerNode.Value !=null)
    {
                        if (objInnerNode.Value.Tostring()== dataGridView1.SelectedRows[0].Cells[0].ToString())
                        {
                            objXMLDoc.RemoveChild(objNode);
     
                            blnFlag = true;
                            break;
                        }
    }
                    }
                    if (blnFlag)
                        break;
                }
                //Save XML
                objXMLDoc.Save(strFilename);
            }
            catch (Exception j)
            {
                MessageBox.Show(j.Message);
            }
    désolé je travail sur mon pc personnel donc pas de visuel studio pour tester avant
    t'as pas trouver de solution azstar ???

  17. #17
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    bonjour
    voila une méthode pour supprimer la node <video> en se basant sur la valeur de la node Fichier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
     
    void supprimerParFichier()
            {
                string strFilename = "Videos.xml";
                bool blnFlag = false;
                XmlDocument objXMLDoc = new XmlDocument();
                objXMLDoc.Load(Application.StartupPath + "/videos.xml");
                //XmlDocument objXMLDoc = ReadXML();
     
                XmlNodeList lstMovies = objXMLDoc.ChildNodes;
                try
                {
     
     
                    foreach (XmlNode objNode in lstMovies)
                    {
                        foreach(XmlNode moviesnode in objNode.ChildNodes)
                        {
                            XmlNodeList MovieDetaill = moviesnode.ChildNodes;
                            if (MovieDetaill[0].InnerText ==dataGridView1.SelectedRows[0].Cells[0].ToString())
                            {
                                objNode.RemoveChild(moviesnode);
                                blnFlag = true;
                                break;
                            }
                        }
                            if (blnFlag)
                                break;
     
                     }
     
     
                    //Save XML
                    objXMLDoc.Save(Application.StartupPath + "/videos.xml");
                }
                catch (Exception j)
                {
                    MessageBox.Show(j.Message);
                }
            }
    et aussi ton fichier xml j'ai fait quelque retouche

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <Videos>
      <Video>
        <FICHIER>C:\Users\benrhaie\Desktop\La classification des donnees est une sorte de fiche d.docx</FICHIER>
        <TITRE>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=4620422</TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCEES>14:52:58</HEUREDERNIERACCEES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE> Dans un</COPIE>
      </Video>
      <Video>
        <FICHIER>C:\Users\benrhaie\Desktop\La classification des donnees est une sorte de fiche d.docx</FICHIER>
        <TITRE>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=4620422</TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCEES>14:52:58</HEUREDERNIERACCEES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE>/14/PDF/p178.pdf</COPIE>
      </Video>
     <Video>
        <FICHIER>d.docx</FICHIER>
        <TITRE>
        </TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCEES>2012-10-08</HEUREDERNIERACCEES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE>rrrrrrrrrrrrrrrrrrrrrrrrrrr</COPIE>
        <aaaa>aaaaaaaaaaaa </aaaa>
        <Category>elemnt ajouter pour ce texte</Category>
      </Video>
    </Videos>
    il faut éviter les lettres accentuées dans les noms des nodes .

  18. #18
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    bonjour
    voila une méthode pour supprimer la node <video> en se basant sur la valeur de la node Fichier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
     
    void supprimerParFichier()
            {
                string strFilename = "Videos.xml";
                bool blnFlag = false;
                XmlDocument objXMLDoc = new XmlDocument();
                objXMLDoc.Load(Application.StartupPath + "/videos.xml");
                //XmlDocument objXMLDoc = ReadXML();
     
                XmlNodeList lstMovies = objXMLDoc.ChildNodes;
                try
                {
     
     
                    foreach (XmlNode objNode in lstMovies)
                    {
                        foreach(XmlNode moviesnode in objNode.ChildNodes)
                        {
                            XmlNodeList MovieDetaill = moviesnode.ChildNodes;
                            if (MovieDetaill[0].InnerText ==dataGridView1.SelectedRows[0].Cells[0].ToString())
                            {
                                objNode.RemoveChild(moviesnode);
                                blnFlag = true;
                                break;
                            }
                        }
                            if (blnFlag)
                                break;
     
                     }
     
     
                    //Save XML
                    objXMLDoc.Save(Application.StartupPath + "/videos.xml");
                }
                catch (Exception j)
                {
                    MessageBox.Show(j.Message);
                }
            }
    et aussi ton fichier xml j'ai fait quelque retouche

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?xml version="1.0" encoding="utf-8"?>
    <Videos>
      <Video>
        <FICHIER>C:\Users\benrhaie\Desktop\La classification des donnees est une sorte de fiche d.docx</FICHIER>
        <TITRE>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=4620422</TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCEES>14:52:58</HEUREDERNIERACCEES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE> Dans un</COPIE>
      </Video>
      <Video>
        <FICHIER>C:\Users\benrhaie\Desktop\La classification des donnees est une sorte de fiche d.docx</FICHIER>
        <TITRE>http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&amp;arnumber=4620422</TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCEES>14:52:58</HEUREDERNIERACCEES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE>/14/PDF/p178.pdf</COPIE>
      </Video>
     <Video>
        <FICHIER>d.docx</FICHIER>
        <TITRE>
        </TITRE>
        <DATECREATION>8 octobre 2012</DATECREATION>
        <HEUREDERNIERACCEES>2012-10-08</HEUREDERNIERACCEES>
        <UTILISATEUR>benrhaie</UTILISATEUR>
        <COPIE>rrrrrrrrrrrrrrrrrrrrrrrrrrr</COPIE>
        <aaaa>aaaaaaaaaaaa </aaaa>
        <Category>elemnt ajouter pour ce texte</Category>
      </Video>
    </Videos>
    il faut éviter les lettres accentuées dans les noms des nodes .
    bonjour azstar
    Lorsque tu selectionne la derniere ligne et clike sur supprimer alors il supprime la premiere ligne ??????

  19. #19
    Membre Expert
    Avatar de azstar
    Homme Profil pro
    Architecte Technique BizTalk/.NET
    Inscrit en
    Juillet 2008
    Messages
    1 198
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Architecte Technique BizTalk/.NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 198
    Par défaut
    rebonjour;

    c'est normal puisque la première ligne et la dernière ligne on le même nom de fichier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <FICHIER>C:\Users\benrhaie\Desktop\La classification des donnees est une sorte de fiche d.docx</FICHIER>
    parce que je me base sur le node fichier pour supprimer le node video

    et ça je ne pense pas qui c'est accepté dans ta conception ??

  20. #20
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2011
    Messages : 59
    Par défaut
    Citation Envoyé par azstar Voir le message
    rebonjour;

    c'est normal puisque la première ligne et la dernière ligne on le même nom de fichier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <FICHIER>C:\Users\benrhaie\Desktop\La classification des donnees est une sorte de fiche d.docx</FICHIER>
    parce que je me base sur le node fichier pour supprimer le node video

    et ça je ne pense pas qui c'est accepté dans ta conception ??
    j'ai la colonne copie qui se différe dans tous les element alors je change comme ça ??:
    if (MovieDetaill[0].InnerText == dataGridView1.SelectedRows[0].Cells[5].ToString())
    je pense a cause du numéro 0 il commnce toujour a supprimer la première element ??

Discussions similaires

  1. [Ajout noeud xml] comment ça marche?
    Par noobiewan kenobi dans le forum Format d'échange (XML, JSON...)
    Réponses: 37
    Dernier message: 19/07/2007, 22h46
  2. [XML] [DOM(XML?)] Suppression d'un noeud XML en php
    Par ribrok dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 30/01/2007, 15h11
  3. [DOM XML] Suppression de noeud XML
    Par xenoox dans le forum Bibliothèques et frameworks
    Réponses: 7
    Dernier message: 02/05/2006, 03h37
  4. Réponses: 3
    Dernier message: 01/04/2005, 09h37
  5. XSL ne parvient pas à lire les noeuds XML ??
    Par yahn dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 27/06/2004, 19h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo