当前位置:首页 > .net读取扩展名为xml的资源文件

.net读取扩展名为xml的资源文件

点击次数:752  更新日期:2010-12-27
\n

<?xml version=”1.0″ encoding=”utf-8″?>
<Convertors xmlns=”http://tempuri.org/~vs24E.xsd”>
<Convertor>
<Name>1</Name>
<Category>1</Category>
<Description>1</Description>
</Convertor>
<Convertor>
<Name>2</Name>
<Category>2</Category>
<Description>2</Description>
</Convertor>
<Convertor>
<Name>3</Name>
<Category>3</Category>
<Description>3</Description>
</Convertor>
</Convertors>


\n


以下方法读取:

private static ConvertorData GetConvertorData()
{
Assembly assembly = typeof(ConvertorProvider).Assembly ;
System.IO.Stream stream = assembly.GetManifestResourceStream(“TextConvertor.Convertor.xml”) ;

ConvertorData data = new ConvertorData() ;
data.ReadXml(stream) ;
return data ;
}
大概是先得到Assembly对象,然后得到流对象,以后就好办了,要不读到XmlDocument,要不读到根据xml文件生成的数据集中。

\n