Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read XML to create resx file

Tags:

c#

.net

xml

resx

I have an XML File

<? xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="Foo">Bar</string>
    <string name="Foo1">Bar1</string>

    // More string Tags here

</resources>

I tried

XMLTextReader reader = new XmlTextReader("FooBar.xml");

ResXResourceWriter writer = new ResXResourceWriter("FooBar.resx");

while(reader.Read())
{
    if(reader.NodeType == XmlNodeType.Element && reader["name"] != null)
       writer.AddResource("What_should_I_write_here", "What_should_I_write_here");
}

How to read this xml so that I can create a resx File.

like image 668
Nikhil Agrawal Avatar asked Aug 04 '12 09:08

Nikhil Agrawal


People also ask

Is Resx an XML?

resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.

How do I open an XML file in Resx?

Open a . resx file in the XML (Text) editor. Press Ctrl+Alt+F or choose ReSharper | Windows | File Structure from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.


1 Answers

I did it finally

XMLTextReader reader = new XmlTextReader("FooBar.xml");

ResXResourceWriter writer = new ResXResourceWriter("FooBar.resx");

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

writer.Generate();
writer.Close();
like image 71
Nikhil Agrawal Avatar answered Oct 06 '22 01:10

Nikhil Agrawal