xmldocument, asp.net


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


How can I do that by using XMLDocument Object in c#?
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:

try this code

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

            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";



                        node1.InsertAfter(newNode, parentNode);


            //Save the changes to New File

            //Save the Existing File

Open in new window

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

From novice to tech pro — start learning today.