0
我有一个关于轮询或检测网站上XML文件更改的问题。我有一个相当硬编码的系统,它读取纽约联储关于他们日常证券借贷的XML文件。它运行良好,我没有问题。我的主要问题是我如何在每个工作日轮询网站的变化。我知道我可以检查XML文件上的“上次修改”字段(或者在this的案例中,“准备”字段),但我很好奇我如何去做这件事,以便在实际上做出更改时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();
}
}
}
谢谢,这似乎是不幸的答案。 – weskpga 2012-07-16 18:20:15