我们目前有这样的代码:
Dim xDoc = XDocument.Load(myXMLFilePath)
我们目前知道如何做到这一点的唯一方法是使用文件路径和模拟(因为此文件位于安全的网络路径上)。
我查看了 MSDN 上的 XDocument.Load,但什么也没看到。
我们目前有这样的代码:
Dim xDoc = XDocument.Load(myXMLFilePath)
我们目前知道如何做到这一点的唯一方法是使用文件路径和模拟(因为此文件位于安全的网络路径上)。
我查看了 MSDN 上的 XDocument.Load,但什么也没看到。
我建议使用 WebRequest 获取流并将流加载到文档中。
该文档说文件参数是“引用文件以加载到新 XDocument 中的 URI 字符串”。此外,我的代码正是这样做的——XDocument.Load
与 URI 一起使用。
//Sample XML
<Product>
<Name>Product1</Name>
<Price>0.00</Price>
</Product>
//Reading XML
XmlTextReader rdr = new XmlTextReader("http://your-url");
XDocument loaded = XDocument.Load(rdr);
//View the loaded contents
//Response.ClearHeaders();
//Response.ContentType = "text/xml;charset=UTF-8";
//Response.Write(loaded);
//Response.End();
var data = from c in loaded.Descendants("Product")
select new
{
name = c.Element("Name").Value,
price = c.Element("Price").Value,
};
foreach (var element in data)
{
//Do something here
}