如何从ANSI转换为XML文件的UTF-8. [英] How to Convert from ANSI to UTF-8 of XML files.
本文介绍了如何从ANSI转换为XML文件的UTF-8.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
在我的项目中,大约有200个ANSI编码的XML文件.我想一次在C Sharp(ADO.net)中以UTF-8格式转换所有这些文件.
如何为该过程制作工具?
提前Thnx
Sumit Shukla
Hi frenzs,
In my project there are about 200 XML file in ANSI encoding. I want to Convert these all files at a time in UTF-8 in a C sharp (ADO.net).
How to make a tool for this process?
Thnx in Advance
Sumit Shukla
推荐答案
与ADO.NET无关.请从问题中删除此标签.
任务很简单:您需要使用ANSI或自动检测的编码读取文件,然后使用UTF-8编码写入文件.自动检测更好,因为可以真正保证输入文件始终以ANSI编写.
如果XML文件不是很大,最简单的方法是使用XmlDocument
编写.
以下是可供选择的XML类的概述:
It has nothing to do with ADO.NET. Please remove this tag from the question.
The task is simple: you need to read a file using either ANSI or auto-detected encoding and write it using UTF-8 encoding. Auto-detected is better because how can you really guarantee that the input file is always written in ANSI.
The simplest approach is to write useXmlDocument
, if the XML files are not extremely big.
Here is the overview of XML classes to choose from:
- 使用
System.Xml.XmlDocument
类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
请参见 ^ ]. - 使用类
System.Xml.XmlTextWriter
和System.Xml.XmlTextReader
;这是最快的读取方法,尤其是您需要跳过一些数据.
请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [
- Use
System.Xml.XmlDocument
class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^]. - Use the classes
System.Xml.XmlTextWriter
andSystem.Xml.XmlTextReader
; this is the fastest way of reading, especially is you need to skip some data.
See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^]. - Use the class
System.Xml.Linq.XDocument
; this is the most adequate way similar to that ofXmlDocument
, supporting LINQ to XML Programming.
See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
这篇关于如何从ANSI转换为XML文件的UTF-8.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文