当前位置:网站首页>C reads XML on the web
C reads XML on the web
2022-06-25 07:44:00 【※※ Bingxin ※※】
One 、 Use LINQ Read
Use Xdocument Upper Load Method , Can quickly load a XML file , And then use LINQ Yes load XML Document for query or other operations , Here is only a simple partial calendar . therefore , Once a set of elements is queried, a set of elements is returned , You can use a simple foreach Loop through each element . The core code is as follows :
/// <summary>
/// Use LINQ Read web Upper xml
/// </summary>
public static void UseLINQ()
{
string sURL = "http://localhost:9058/GameServerInfo/XMLFile.xml";
XDocument oXDoc = XDocument.Load(sURL);
var qurey = from e in oXDoc.Descendants()
where e.NodeType == XmlNodeType.Element
select new
{
ElementName=e.Name.ToString(),
ElementValue=e.Value
};
foreach(var elementInfo in qurey)
{
HttpContext.Current.Response.Write(string.Format("ElementName->{0} ElementValue->{1}<br />", elementInfo.ElementName, elementInfo.ElementValue));
}
}
Two 、 Use XmlReader Constructors
Of course, you can also use the URL Of XmlReader.Create Method to complete the operation , It uses a XmlUrlResolver Class to detect the incoming URL, Then open a path to the URL Representative XML The document flow . To specify the settings on the reader , You can use another Create overloaded , It's also through a XmlReaderSetting Examples accomplish this . The code is as follows :
/// <summary>
/// Use XmlReader Constructors
/// </summary>
public static void UseXmlReader()
{
string sURL = "http://localhost:9058/GameServerInfo/XMLFile.xml";
using(XmlReader read=XmlReader.Create(sURL))
{
while(read.Read())
{
switch (read.NodeType)
{
case XmlNodeType.Element:
HttpContext.Current.Response.Write(string.Format("ElementName->{0} <br />", read.Name));
break;
case XmlNodeType.Text:
HttpContext.Current.Response.Write(string.Format("ElementValue->{0}<br />", read.Value));
break;
case XmlNodeType.CDATA:
HttpContext.Current.Response.Write(string.Format("ElementValue->{0}<br />", read.Value));
break;
//other
}
}
}
}
边栏推荐
- Modular programming of oled12864 display controlled by single chip microcomputer
- Three years of continuous decline in revenue, Tiandi No. 1 is trapped in vinegar drinks
- Lebel only wants an asterisk in front of it, but doesn't want to verify it
- ELK + filebeat日志解析、日志入库优化 、logstash过滤器配置属性
- realsense d455 semantic_ Slam implements semantic octree mapping
- Redis learning notes
- Tempest HDMI leak receive 2
- IAR compiler flashback
- My debut is finished!
- Summary of small problems in smartbugs installation
猜你喜欢
[batch dos-cmd command - summary and summary] - add comment command (REM or::)
Chuantu microelectronics ca-if1051 can-fd transceiver
Path planner based on time potential function in dynamic environment
【批处理DOS-CMD命令-汇总和小结】-cmd扩展命令、扩展功能(cmd /e:on、cmd /e:off)
What common APIs are involved in thread state changes
无“米”,也能煮“饭”利用“点云智绘”反演机载LiDAR林下缺失地面点攻略
Tempest HDMI leak receive 1
Misunderstanding of switching triode
图扑软件数字孪生 3D 风电场,智慧风电之海上风电
Modular programming of oled12864 display controlled by single chip microcomputer
随机推荐
C#获取exe的版本号-文件版本and程序集版本
The method of judging whether triode can amplify AC signal
Explain distributed raft with dynamic diagram
Access to foreign lead domain name mailbox
Cglib dynamic proxy
国外LEAD域名邮箱获取途径
Introduction to Sichuan Tuwei ca-is3082wx isolated rs-485/rs-422 transceiver
Ca-is1200u current detection isolation amplifier has been delivered in batch
smartBugs安装小问题总结
Full range of isolator chips with integrated isolated power supply
Evolution of Alibaba e-commerce architecture
Understand the reasons for impedance matching of PCB circuit board 2021-10-07
Misunderstanding of switching triode
三年营收连续下滑,天地壹号困在醋饮料里
搞清信息化是什么,让企业转型升级走上正确的道路
Distributed quorum NWR of the alchemy furnace of the Supreme Master
What is the difference between norflash and nandflash
STL tutorial 4- input / output stream and object serialization
Shell tips (134) simple keyboard input recorder
Pit encountered by pytorch: why can't l1loss decrease during model training?