A method to read a resource file that has an XML extension

Source: Internet
Author: User
Tags resource

Today, when refactoring code, you want to embed the following XML file in the assembly and read at run time:

<?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>

Looked everywhere, all about reading. txt and. resx-type embedded resources, and then a flash, try the following methods:

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;
} 

It is probably the first to get the Assembly object, and then get the stream object, then it is good to do, or read the XmlDocument, or read the data set based on the XML file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.