locked
Customizing the .resx file. RRS feed

  • Question

  • Hi,

    A sample line in appResources.resx file as below.

     <data name="Version" xml:space="preserve">
        <value>1.2</value>
        <comment>beta </comment>
      </data>

    Is there a way, I can add custom attribute as below programmatically using ResxWriter or any other way.

     <data name="Version" NewNameSpace:NewAttribute="SomeValue" xml:space="preserve">
        <value>1.2</value>
        <comment>beta </comment>
      </data>

    Regards

    Monday, August 4, 2014 5:39 PM

Answers

  • Hi JiyaDesai,

    First with ResXResourceWriter Class  to write resources in an XML resource (.resx) file.

    After you done this, you can use XDocument.Load () method to load the document.

    Find the node “data”, then add custom node.

    I have write a small demo as below

      ResXResourceWriter w = new ResXResourceWriter(@"D:\ResXForm.resx");
                string i = "1.2";
                w.AddResource("happyDude", i);
                w.AddResource("welcomeString", "Hello new resource format!");
    
                w.Generate();
                w.Close();
    
                XDocument a = XDocument.Load(@"D:\ResXForm.resx");
    
                foreach (XElement element in a.Descendants("data"))
                {
                    XElement xAttr = new XElement("comment", "beta");
                    element.Add(xAttr);
                }
                a.Save(@"D:\ResXForm.resx");

    Have a nice day!

    Kristin

    • Proposed as answer by Ioana Vasilescu Tuesday, August 5, 2014 10:58 AM
    • Marked as answer by Kristin Xie Thursday, August 7, 2014 10:16 AM
    Tuesday, August 5, 2014 7:27 AM