开发者

C# connect to URL which gives a xml document

How can I in C# call a URL which gives m开发者_运维技巧e a xml file, and then process that xml file for example for parsing.


To download an XML file onto your hard disk you can simply do.

XDocument doc = XDocument.Load(url);
doc.Save(filename);

How you parse it is a different matter and there are several different ways to do it. Here is a SO question that covers the subject. You can also checkout the LINQ to XML reference on MSDN.


using System; 
using System.IO; 
using System.Net; 
using System.Text; 

... 

    public static void GetFile 
            ( 
            string strURL, 
            string strFilePath 
            ) 
        { 

            WebRequest myWebRequest = WebRequest.Create(strURL);  

            WebResponse myWebResponse = myWebRequest.GetResponse();  

            Stream ReceiveStream = myWebResponse.GetResponseStream(); 

            Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); 

            StreamReader readStream = new StreamReader( ReceiveStream, encode ); 

            string strResponse=readStream.ReadToEnd(); 

            StreamWriter oSw=new StreamWriter(strFilePath); 

            oSw.WriteLine(strResponse); 

            oSw.Close(); 

            readStream.Close(); 

            myWebResponse.Close(); 

        } 

from : http://zamov.online.fr/EXHTML/CSharp/CSharp1.html

XML Parser:

http://www.c-sharpcorner.com/uploadfile/shehperu/simplexmlparser11292005004801am/simplexmlparser.aspx

Just pass the stream to the XML Parser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜