更新时间:2022-10-22 21:38:20
访问这里....
http://***.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://***.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