读取HTTP地址XML文件 [英] Read an XML file from http address

查看:118
本文介绍了读取HTTP地址XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用C#/。NET从像这样一个源读取XML文件: https://10.1.12.15/xmldata?item=all

这基本上只是一个XML文件。

的StreamReader不喜欢这一点。

什么是阅读链接的内容的最佳方式?

该文件看起来像这样:

   - < RIMP>
      - <恒指>
       <&SBSN GT; CZ325000123< / SBSN>
       <&SPN GT;的ProLiant DL380p Gen8< / SPN>
       <&UUID GT; BBBBBBGGGGHHHJJJJ< / UUID>
       &所述; SP→1&下; / SP>
       < cUUID> 0000-000-222-22222-333333333333< / cUUID>
- <虚拟的GT; ...


解决方案

另一种方式来做到这一点是使用的XmlDocument 类。很多世界各地的服务器仍在运行.NET Framework< 3.0所以这是很好的知道,这个类仍然存在沿着的XDocument 如果你正在开发将在服务器上运行的应用程序。

 字符串URL = @https://10.1.12.15/xmldata?item=all
XmlDocument的xmlDoc中=新的XmlDocument();
xmlDoc.Load(URL);

I need to read an xml file using c#/.net from a source like so: https://10.1.12.15/xmldata?item=all

That is basically just an xml file.

StreamReader does not like that.

What's the best way to read the contents of that link?

The file looks like so:

- <RIMP>
     - <HSI>
       <SBSN>CZ325000123</SBSN> 
       <SPN>ProLiant DL380p Gen8</SPN> 
       <UUID>BBBBBBGGGGHHHJJJJ</UUID> 
       <SP>1</SP> 
       <cUUID>0000-000-222-22222-333333333333</cUUID> 
- <VIRTUAL>...

解决方案

Another way to do this is using the XmlDocument class. A lot of servers around the world are still running .Net Framework < 3.0 so it's good to know that this class still exists alongside XDocumentin case you're developing an application that will be run on a server.

string url = @"https://10.1.12.15/xmldata?item=all";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(url);

这篇关于读取HTTP地址XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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