MSDN > 論壇首頁 > XML Paper Specification (XPS) > how to find the value xml file and update
發問發問
 

問題how to find the value xml file and update

  • 2009年6月17日 下午 12:53Ranganathan Palanisamy 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

     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.

所有回覆

  • 2009年6月18日 上午 06:55Ranganathan Palanisamy 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    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.