txt转xml问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 03:22:06
假设txt文件中有以下字段:
Name : ***
Version: *.*.*
Size : 10 M
Repo : installed
Summary: 5 - Beta
Description: ********
有没有什么办法可以把这些信息自动转为xml?
如:<Products>
<Product>01
<Name>***</Name>
<Version>*.*.*</Version>
<Size>10M</Size>
......
</Product>
</Products>

最上面增加 using System.Xml;
private static XmlDocument xmlDoc = new XmlDocument();
static string fileName = "C:\\config.xml";//配置文件的路径、名

static void Main(string[] args)
{
CreateXmlConfigFile();
}

public static void CreateXmlConfigFile()
{

XmlTextWriter xmlWriter;
xmlWriter = new XmlTextWriter(fileName, Encoding.Default);//creat //string fileName = Application.StartupPath + "\\config.xml";
xmlWriter.Formatting = Formatting.Indented;//自动缩进格式

xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Products");

xmlWriter.WriteEndElement();

xmlWriter.Close();
AddXmlNode("***", "*.*.*", "10M", "aaa","www","描述");
AddXmlNode("***", "*.*.*", "10M", "aaa", "www", "描述");
AddXmlNode("**