尝试将xml绑定到resource.resx以完成全局化
这是我的代码,
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();
我的xml是
<?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>
现在我的问题是只有在我设置整个路径时才会获得xml 可以帮助我吗
我也试过,
System.Xml.XmlTextReader reader = new XmlTextReader("~/Swedish.xml");
System.Xml.XmlTextReader reader = new XmlTextReader(@"/Swedish.xml");
答案 0 :(得分:0)
我的问题是当我更改代码时清除了一些内容,
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);
但有时出现运行时错误