Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在网站更改时自动加载新文件_C#_Xml_Rss_Xml Parsing - Fatal编程技术网

C# 如何在网站更改时自动加载新文件

C# 如何在网站更改时自动加载新文件,c#,xml,rss,xml-parsing,C#,Xml,Rss,Xml Parsing,关于轮询或检测网站上XML文件的更改,我有一个问题。下面我有一个相当硬编码的系统,它从纽约联邦储备银行读取关于他们日常证券借贷的XML文件。它运行良好,我对此没有异议。我的主要问题是我如何在每个工作日对网站进行民意调查以了解变化。我知道我可以检查XML文件上的“Last Modified”(最后修改)字段(或者“Prepared”(准备好的)字段),但我很好奇如何进行检查,以便在实际更改XML站点时,我的计算机自动加载和解析新的XML文件。这些信息一出来就得到对我来说非常重要,所以每X分钟轮询一

关于轮询或检测网站上XML文件的更改,我有一个问题。下面我有一个相当硬编码的系统,它从纽约联邦储备银行读取关于他们日常证券借贷的XML文件。它运行良好,我对此没有异议。我的主要问题是我如何在每个工作日对网站进行民意调查以了解变化。我知道我可以检查XML文件上的“Last Modified”(最后修改)字段(或者“Prepared”(准备好的)字段),但我很好奇如何进行检查,以便在实际更改XML站点时,我的计算机自动加载和解析新的XML文件。这些信息一出来就得到对我来说非常重要,所以每X分钟轮询一次并没有像我希望的那样有效。有什么想法吗

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.IO;
using System.Xml.Linq;
using System.Diagnostics;

namespace ConsoleApplication2 {
    class Program {
        static void Main(string[] args) {
            // XML text reader stuff
            //XmlReader textReader = XmlReader.Create("http://www.newyorkfed.org/markets/seclend/xml/v3_0/secLendingXML.cfm");
            XmlTextReader textReader = new XmlTextReader("http://www.newyorkfed.org/markets/seclend/xml/v3_0/secLendingXML.cfm");
            //SyndicationFeed feed = SindicationFeed.Load(textReader);
            //XmlTextReader textReader = new XmlTextReader("LOCATION");
            //string[] Fed_Array = new string[] {"Actual Available to Borrow", "Outstanding Loans",
            //"Par Submitted", "Par Accepted", "WTD Average Rate"};
            int j = 0;
            int icount = 0;
            using(StreamWriter writer = new StreamWriter("LOCATION"))
            //using (StreamWriter writer = new StreamWriter("LOCATION"))    
            while (textReader.Read()) {
                switch (textReader.NodeType) {
                case XmlNodeType.Element:
                    for (int i = 0; i < textReader.AttributeCount; i++) {
                        textReader.MoveToAttribute(i);
                        switch (textReader.Name) {
                        case "securityMaturityDate":
                            string textvalmatd = textReader.Value;
                            if (i == 0 && icount == 0) {
                                writer.Write("N/A,");
                                Console.Write("N/A,");
                                icount = 1;
                                i = -1;
                            } else {
                                writer.Write(textvalmatd + ",");
                                Console.Write(textvalmatd + ",");
                                icount = 0;
                            }
                            break;
                        case "couponRate":
                            string textvalcoup = textReader.Value;
                            writer.Write(textvalcoup + ",");
                            Console.Write(textvalcoup + ",");
                            break;
                        case "securityType":
                            string textvalsec = textReader.Value;
                            writer.Write(textvalsec + ",");
                            Console.Write(textvalsec + ",");
                            j = 0;
                            break;
                        case "value":
                            string textval = textReader.Value;
                            writer.Write(textval + ",");
                            Console.Write(textval + ",");
                            j = j + 1;
                            if (j > 4) {
                                writer.Write(Environment.NewLine);
                                Console.Write(Environment.NewLine);
                            }
                            break;

                        }
                    }
                    break;
                }
            }
        }

        private static IDisposable StreamWriter(string p) {
            throw new NotImplementedException();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Xml;
使用System.IO;
使用System.Xml.Linq;
使用系统诊断;
命名空间控制台应用程序2{
班级计划{
静态void Main(字符串[]参数){
//XML文本阅读器
//XmlReader textReader=XmlReader.Create(“http://www.newyorkfed.org/markets/seclend/xml/v3_0/secLendingXML.cfm");
XmlTextReader textReader=新的XmlTextReader(“http://www.newyorkfed.org/markets/seclend/xml/v3_0/secLendingXML.cfm");
//SyndicationFeed=sinndicationFeed.Load(文本阅读器);
//XmlTextReader textReader=新的XmlTextReader(“位置”);
//string[]Fed_Array=新字符串[]{“实际可借”、“未偿还贷款”,
//“提交Par”、“接受Par”、“WTD平均费率”};
int j=0;
int-icount=0;
使用(StreamWriter=newstreamwriter(“位置”))
//使用(StreamWriter=newstreamwriter(“位置”))
while(textReader.Read()){
开关(textReader.NodeType){
case XmlNodeType.Element:
for(int i=0;i4){
writer.Write(Environment.NewLine);
Console.Write(Environment.NewLine);
}
打破
}
}
打破
}
}
}
私有静态IDisposable StreamWriter(字符串p){
抛出新的NotImplementedException();
}
}
}

除非美联储提供某种事件表明新文件可用(我对此表示怀疑),理论上最好的办法是下载最新的XML文件,并检查它是否比以前的文件更新


如果文件确实每天发布一次,您可以生成自己的统计数据,确切地说,文件每天发布的时间。在一个围绕典型发布时间的窗口中加强您的轮询(但是,请确保您在轮询频率中没有违反任何服务条款)。

谢谢,不幸的是,这似乎是答案。