Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

asp.net xml

<Auctions>
  <Auction>
    <FirstName>adsfasd</FirstName>
    <LastName>Yuxcad</LastName>    
    <ID>IiY+D4SIrRpXtEUUu0uy0j1G0LdUJ9bWPj6+ZvO24yE2szPHUFXMfYXirGmWC7asdfasdfsdaO</ID>
    <Status>Pending</Status>
    <Condition>OLD</Condition>
    <Manufacturer>Rickasdfasdy</Manufacturer>
    <CurrencyType>USD</CurrencyType>
    <HighestBid></HighestBid>
    <Bid>      
     
    </Bid>
  </Auction>
  <Auction>
    <FirstName>adsfasdadfasdf</FirstName>
    <LastName>Yusdf</LastName>    
    <ID>IiY+D4SIrRpXtEUUu0uy0j1G0LdUJ9bWPj6+ZvO24yE2szPHUFXMfYXirGmWC7aO</ID>
    <Status>Pending</Status>
    <Condition>OLD</Condition>
    <Manufacturer>Rickasdfy</Manufacturer>
    <CurrencyType>USD</CurrencyType>
    <HighestBid></HighestBid>
    <Bid>
     
     
    </Bid>
  </Auction>
</Auctions>

Read/Find the ID = "IiY+D4SIrRpXtEUUu0uy0j1G0LdUJ9bWPj6+ZvO24yE2szPHUFXMfYXirGmWC7aO"
and update <HighestBid>1000</HighestBid>


How can I do that by using XMLDocument Object in c#?
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Hi,

try this code

 

 public void UpdateXmlFile()
        {
            XmlDocument myXmlDocument = new XmlDocument();
            string fileName = @"D:\Auctions.xml";
            myXmlDocument.Load(fileName);

            XmlNode node = myXmlDocument.DocumentElement;

            foreach (XmlNode node1 in node.ChildNodes)
            {
                foreach (XmlNode node2 in node1.ChildNodes)
                {
                    if (node2.Name == "ID")
                    {
                        string nodeValue = node2.InnerText; // Get the ID Value
                    }

                    //Update the Node
                    if (node2.Name == "HighestBid")
                    {
                        // Update the value
                        int newValue = 1000;
                        node2.InnerText = newValue.ToString();
                    }
                }
            }

            //Save the changes to New File
            myXmlDocument.Save(@"D:\a1.xml");

            //Save the Existing File
            myXmlDocument.Save(fileName);
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial