您的位置:首页 > 其它

给自己的眼睛放放假

2009-02-05 10:09 197 查看
又回到了那个相当无聊的保守项目中!还是做中文化,两千多条资源,两天内由日文翻译成中文。我一直纳闷的时公司有专业翻译,为什么却还非得拿到项目组中来让我们这些50音图都读不全的人“翻译”?是不是怕我们闲着会头痛?呵呵。

不说废话了。其实已经有了一份上个版本的中文资源文件,这次只是增加了一部分新的条目而已。问题是原来的资源文件只有xml版本的,而要把它放到Excel中对应的位置去只能手动,负值,查找,粘贴。两千多条虽然不算太多,但操作起来还是比较费时间的。于是准备写个小的工具自动将xml文件中的资源匹配并填充到Excel文件中。很久没写代码了,几行代码写了我一两个小时。。。

xml文件结构

private void button1_Click(object sender, EventArgs e)

private static Dictionary<string, string> GetXMLValue(string xmlPath)

{

XPathNavigator nav;

XPathDocument docNav;

Dictionary<string, string> dictionary = new Dictionary<string, string>();

docNav = new XPathDocument(xmlPath);

nav = docNav.CreateNavigator();

nav.MoveToRoot();

//Move to the first child node (comment field).

nav.MoveToFirstChild();

do

{

//Find the first element.

if (nav.NodeType == XPathNodeType.Element)

{

//Determine whether children exist.

if (nav.HasChildren == true)

{

//Move to the first child.

nav.MoveToFirstChild();

//Loop through all of the children.

do

{

//Display the data.

string value = nav.Value;

nav.MoveToFirstAttribute();

string name = nav.Value;

if (!dictionary.ContainsKey(name))

{

dictionary.Add(name, value);

}

nav.MoveToParent();

} while (nav.MoveToNext());

}

}

} while (nav.MoveToNext());

return dictionary;

}

写的有点乱,记录一下,以后有类似需求时修改下就可以继续使用了。毕竟这个破烂保守项目经常做的就是这种事情
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: