ASP.net load XML file from URL

后端 未结 1 883
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 08:38

Trying to just simply parse an XML file;

    protected void Page_Load(object sender, EventArgs e)
    {

        XmlDocument xdoc = new XmlDocument();//xml d         


        
相关标签:
1条回答
  • 2020-12-11 09:04

    try this :

    protected void Page_Load(object sender, EventArgs e)
    {
    
        XmlDocument xdoc = new XmlDocument();//xml doc used for xml parsing
    
        xdoc.Load(
            "http://latestpackagingnews.blogspot.com/feeds/posts/default"
            );//loading XML in xml doc
    
        XmlNodeList xNodelst = xdoc.DocumentElement.SelectNodes("entry");//reading node so that we can traverse thorugh the XML
    
        foreach (XmlNode xNode in xNodelst)//traversing XML 
        {
            litFeed.Text += "read";
        }
    
    }
    

    LoadXml is waiting for an xml string directly, where Load can use an uri to grab the xml data. With your code, the xml parser was actually trying to parse the adress as xml, not the content at the uri location.

    [Edit] you may take a look at the builtin feed processing classes of the .Net Framework. These classes are in the System.ServiceModel.Syndication namespace. They can to the parsing job for you quite easily.

    0 讨论(0)
提交回复
热议问题