如何在不生成.xml文件的情况下读取C#中的xml字符串 [英] how to read the xml String in C# without making .xml file

查看:73
本文介绍了如何在不生成.xml文件的情况下读取C#中的xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   Root  >  
< PhononRequestID > 6719 < / PhononRequestID >
< LeadID > lead01 < / LeadID >
< VisitorNumber > 987654154 < / VisitorNumber >
< / Root >

解决方案

< blockquote>访问这里....





http://stackoverflow.com/questions/13136920/read-an-xml-string-in-c-sharp [ ^ ]


一切都取决于xml的来源。基于此,您需要选择相应的API。

使用XML的基本方法是XmlDocument对象。您可以通过各种加载方法填充它,具体取决于您拥有的xml的来源。



 XmlDocument xdoc =  new  XmlDocument(); 
// 如果xml来自字符串
string myXml = < myxml> data< / myxml>;
xdoc.LoadXml(myXml);
// 如果xml来自其他数据源,请创建相应的阅读器
XmlReader阅读器; // 根据类型获取有效实例
xdoc.Load(reader);
// 如果来自流
StreamReader sReader;
xdoc.Load(sReader);
// 使用XmlDocument属性来处理xml



您还可以使用LINQ to XML来解析XML


<Root>
<PhononRequestID>6719</PhononRequestID>
<LeadID>lead01</LeadID>
<VisitorNumber>987654154</VisitorNumber>
 </Root>

解决方案

visit here....


http://stackoverflow.com/questions/13136920/read-an-xml-string-in-c-sharp[^]


Everything depends on the source of the xml. Based on that you will need to select the corresponding API.
The basic method of working with XML is XmlDocument object. You can populate this through its various load methods depending on the source of the xml you have.

XmlDocument xdoc = new XmlDocument();
// if xml coming via string
string myXml = "<myxml>data</myxml>";
xdoc.LoadXml(myXml);
// If xml coming via some other datasource, create a corresponding reader
XmlReader reader; // get a valid instance depending on type
xdoc.Load(reader);
// If coming via stream
StreamReader sReader;
xdoc.Load(sReader);
// use XmlDocument properties to work with the xml


You can also use LINQ to XML to parse XML


这篇关于如何在不生成.xml文件的情况下读取C#中的xml字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆