views:

56

answers:

1

Hello I wanna add a Test (common) attribute to all my XML files. So that I could use it as a common attribute when I wanna test them.

I tried CreateAttribute but Linq dosen't recognize it

I tried "xElement.Add(new XAttribute("Test", value));" but it also didn't work Any Suggestions?

Thanks

Here for example is a code

    public void updateXmlFile(string strFileName)
    {
        XDocument oXDoc = XDocument.Load(strFileName);
        XElement oDcElement = oXDoc.Root.FirstNode as XElement;

        //Generate a Unique String to replace the original attribute value
        string newValue = GetUniqueKey();

        //oDcElement.Add(new XAttribute("Test", newValue)); /*NullReferenceException*/

        oDcElement.Attribute("Remark").Value = newValue; //This changes only the Remark Attribute
        oXDoc.Save(strFileName);                         //which isn't available in all XMLs

    }

I wanna add an additional, common value to the XMLs I pass through this method and give it a random value

My goal is to be able to make changes on an XML then compare it against the original copy in another folder

A: 

Use SetAttribute:

oDcElement.SetAttributeValue("Test", newValue);
Patrick Steele
I figured I can't do it since I'm retrieving Data from the DB and if I wanna add an attribute I have to add an extra coloumn to the DB.
Reda
Your original question says nothing about a DB. It's just adding a new attribute to a node of an XML file loaded from the filesystem. I don't understand what your comment means.
Patrick Steele
Sorry about that I'l be more clear next time
Reda