0

How can i modify the value of an attribute within an xml loaded using Loadxml()?

I'm trying to update the xml string stored in my db. For that, i used the following code:

XmlDocument doc = new XmlDocument();
        doc.LoadXml(project.ProjectData);
        XmlNodeList pNodes = doc.SelectNodes("project");
        foreach (XmlNode pNode in pNodes)
        {
            XmlAttribute lPDAttribute = pNode.Attributes["lastPubDate"];
            if (lPDAttribute != null)
            {
                string currentValue = lPDAttribute.Value;
                if (string.IsNullOrEmpty(currentValue))
                {
                    lPDAttribute.Value = project.PublishDate.ToString();
                }
            }
        }

What should i do to save the updated attribute within my current xml? Please help.

1
  • Can you give us some more info about the scope? Are you creating the "project" node yourself? Commented Oct 17, 2011 at 6:59

2 Answers 2

2

I think you should add the below code line

project.ProjectData = doc.InnerXml
Sign up to request clarification or add additional context in comments.

Comments

2

you can store doc.InnerXml as a string in your db

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.