xmldocument, asp.net

<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>
    <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>
    <Bid>
         
   </Bid>
  </Auction>
</Auctions>

I have below xml format. What I would like to do is:

Read/Find the ID = "IiY+D4SIrRpXtEUUu0uy0j1G0LdUJ9bWPj6+ZvO24yE2szPHUFXMfYXirGmWC7aO"
if isFound Add record within the <Bid></Bid>

like below

<Bid>
     <Log>
      <price>100</price>
      <createdDateTime>1:00pm</createdDateTime>
      <createdBy>Me</createdBy>
     </Log>
</Bid>
 

How can I do that by using XMLDocument Object in c#?
LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

try this code

 
public void AddNewNodeToXMLFile()
        {
            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 ID record found add the <Bid> tags
                    if (node2.Name == "ID")
                    {
                        string nodeValue = node2.InnerText; // Get the ID Value

                        XmlNode parentNode = node1.LastChild;

                        //Create a new node.
                        XmlNode newNode = myXmlDocument.CreateNode(XmlNodeType.Element, "Bid", null);

                        XmlNode logNode = myXmlDocument.CreateNode(XmlNodeType.Element, "Log", null);

                        //create price node
                        XmlNode nodePrice = myXmlDocument.CreateElement("Price");
                        //add value for it
                        nodePrice.InnerText = "100";

                        //create CreatedDateTime node
                        XmlNode nodeDate = myXmlDocument.CreateElement("CreatedDateTime");
                        nodeDate.InnerText = DateTime.Now.ToString();

                        XmlNode nodeCreatedBy = myXmlDocument.CreateElement("createdBy");
                        nodeCreatedBy.InnerText = "Me";

                        newNode.AppendChild(logNode);

                        logNode.AppendChild(nodePrice);
                        logNode.AppendChild(nodeDate);
                        logNode.AppendChild(nodeCreatedBy);

                        node1.InsertAfter(newNode, parentNode);

                        break;
                    }
                }
            }

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

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

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.