A Method for reading resource files with an extension of XML

Source: Internet
Author: User
When refactoring the code today, I want to embed the following XML file into the assembly and read it at runtime:

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

After reading the embedded resources of the. txt and. resx types, I tried the following methods:

Private Static convertordata getconvertordata ()
{
Assembly = typeof (convertorprovider). assembly;
System. Io. Stream stream = assembly. getmanifestresourcestream ("textconvertor. convertor. xml ");

Convertordata DATA = new convertordata ();
Data. readxml (Stream );
Return data;
}

Probably it is to get the Assembly object first and then get the stream object, and then it will be easy to do, or read the xmldocument, or the data set generated 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.