惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - karoc

《重构-改善既有代码的设计》读书笔记 扩展GridView,增加单选按钮列 任务开始时间和完成时间 最大长度验证控件:MaxLengthValidator 又是关于AjaxControlToolkit的ModalPopup的问题 有个总结 使用svn的小插曲 开发小经验总结(不断更新) 今天发现一个VS2008中文版和英文版的差别 解决DocType引起AjaxTookit的ModulPopup显示异常问题的方法 Reporting Services 2005 常见问题解决方法(不断更新) - karoc 用VSTO开发Project插件心得 自定义MemberShipProvider和PersonalizationProvider使用WebParts实现个性化页面 - karoc 在线修改KeyValue配置节 瞎搞八搞,另类PageBase 改造Duwamish中的Configuration 直接用Response输出可以加批注的Excel C#控制Windows Messenger和Windows Live Messenger窗口发送消息 用C#+WMI实现获取w3wp进程对应的应用程序池
一个读取扩展名为xml的资源文件的方法
karoc · 2006-11-27 · via 博客园 - karoc

今天重构代码时,想把如下xml文件嵌入程序集中,在运行时读取:

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

到处找了一番,都是关于读取.txt和.resx类型的嵌入资源的,后来灵光一现,试出以下方法:

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文件生成的数据集中。