Fazer uma PerguntaFazer uma Pergunta
 

Perguntahow to find the value xml file and update

  • quarta-feira, 17 de junho de 2009 12:53Ranganathan Palanisamy Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

     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 as Respostas

  • quinta-feira, 18 de junho de 2009 6:55Ranganathan Palanisamy Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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.