Formular una preguntaFormular una pregunta
 

Preguntahow to find the value xml file and update

  • miércoles, 17 de junio de 2009 12:53Ranganathan Palanisamy Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

     Hi Expects

                        How to find the particular value particular value and update  particular xml element value in asp.net in c#.net

     xml format

     <paddress>
        <autoid>0</autoid>
        <fname>Ranganathan</fname>
        <lname>palanisamy</lname>
        <address>bangalore</address>
        <mobile>9886974230</mobile>
        <phone>04295287563</phone>
        <mail>ranganathan@gmail.com</mail>
      </paddress>

    my problem is 

       programming wise find <autoid> and how to update fname,lname,address,mobile,phone & mail

     plz share the example code

    thanks for sharing  your knowelege
    Ranganathan.P., Software Developer., Bangalore India.

Todas las respuestas

  • jueves, 18 de junio de 2009 6:55Ranganathan Palanisamy Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    thnaks for viewers

    i got solution

       XmlDocument doc = new XmlDocument();
    doc.Load("C:\\YourXmlFile.xml");
    XmlNodeList nodes = doc.GetElementsByTagName("autoid");

    foreach (XmlNode node in nodes)
    {
    if (node.InnerText == "0")//If autoid is 0
    {
    XmlNode ParentNode = node.ParentNode;
    string[] strNewList = {"autoid","newfname","newlname","newAddress","newMobile","newPhone","newMail"};
    for (int i = 1; i < ParentNode.ChildNodes.Count; i++)
    {
    node.ParentNode.ChildNodes[i].InnerText = strNewList[i];
    }
    }
    }
    doc.Save("C:\\YourXmlFile.xml");

    Ranganathan.P., Software Developer., Bangalore India.