Search code examples
c#xmlglobalization

read xml and write it inside resource.resx


Am try to bind xml to resource.resx inorder to complete globilazation

this is my code,

            System.Xml.XmlTextReader reader = new XmlTextReader("..//Swedish.xml");

            ResXResourceWriter writer = new ResXResourceWriter("..//App_GlobalResources/Resource.sv-SE.resx");

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name == "string")
                    writer.AddResource(reader.GetAttribute("name"), reader.ReadString());
            }

            writer.Generate();
            writer.Close();

And my xml is

<?xml version="1.0" encoding="utf-8" ?>
 <resources>
 <string name="Account"> konto </string>
 <string name="AccountDetails">Kontouppgifter</string>
 <string name="CompanyManagement">Företagsledning</string>
 <string name="Logout">Logga ut</string>
  </resources>

Now my problem is Am getting xml only if i set the whole path Can Guys help me

i also try by,

     System.Xml.XmlTextReader reader = new XmlTextReader("~/Swedish.xml");
     System.Xml.XmlTextReader reader = new XmlTextReader(@"/Swedish.xml");

Solution

  • My problem is some what cleared when I changed code,

     string xmlPath = Server.MapPath("~/XMLFile1.xml");
     string resourcePath = Server.MapPath("~/LocalResource/Resource.sv-SE.resx");
     System.Xml.XmlTextReader reader = new XmlTextReader(xmlPath);
     ResXResourceWriter writer = new ResXResourceWriter(resourcePath);
    

    but Some time run-time error is happenning