从流式XML文件中解析和提取值?

时间:2022-05-10 15:43:13

After much ado, I managed to create a restful service in asp.net MVC following Omar's brilliant Restful Asp.net article

在经历了这么多的麻烦之后,我按照Omar精彩的restful asp.net文章,在asp.net MVC中创建了一个restful服务

Just one little thing remains.

只剩下一件小事。

My Asp.Net MVC controller returns an XML file , which has this tag

我的Asp。Net MVC控制器返回一个XML文件,它有这个标签

< FileCode > 24233224< / FileCode >

This is a console application I use to send a Get request which gives me the whole Xml file

这是我用来发送Get请求的控制台应用程序,它给了我整个Xml文件

        //Generate get request
        string url = "http://localhost:1193/Home/index?File=343456789012286";
        HttpWebRequest GETRequest = (HttpWebRequest)WebRequest.Create(url);

        GETRequest.Method = "GET";
        GETRequest.ContentType = "text/xml";
        GETRequest.Accept = "text/xml";

        Console.WriteLine("Sending GET Request");
        HttpWebResponse GETResponse = (HttpWebResponse)GETRequest.GetResponse();
        Stream GETResponseStream = GETResponse.GetResponseStream();
        StreamReader sr = new StreamReader(GETResponseStream);

        Console.WriteLine("Response from Server");

       // This writes whole file on screen
       Console.WriteLine(sr.ReadToEnd());

I could perhaps save this file and then use Linq to parse it, but can't I just get the value in my tag out without saving it ? I simply need the FileCode

我也许可以保存这个文件,然后使用Linq解析它,但是我不能在不保存它的情况下就把标签中的值取出来吗?我只需要FileCode。

Thankyou :)

谢谢:)

1 个解决方案

#1


1  

Yuo could emply the XPathReader (source download).

你可以空出XPathReader(源下载)。

It comes with source and testsuite.

它附带了源代码和testsuite。

What it gives you is the ability to work with highlevel query constructs (XPath) in streaming mode.

它使您能够在流模式下使用高级查询结构(XPath)。


There is also a similar article on CodeProject: Fast screen scraping with XPath over a modified XmlTextReader and SgmlReader

在CodeProject上还有一篇类似的文章:使用XPath在修改后的XmlTextReader和SgmlReader上快速抓取屏幕

#1


1  

Yuo could emply the XPathReader (source download).

你可以空出XPathReader(源下载)。

It comes with source and testsuite.

它附带了源代码和testsuite。

What it gives you is the ability to work with highlevel query constructs (XPath) in streaming mode.

它使您能够在流模式下使用高级查询结构(XPath)。


There is also a similar article on CodeProject: Fast screen scraping with XPath over a modified XmlTextReader and SgmlReader

在CodeProject上还有一篇类似的文章:使用XPath在修改后的XmlTextReader和SgmlReader上快速抓取屏幕