Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • rendervouz 6 posts 126 karma points
    Sep 08, 2016 @ 08:41
    rendervouz
    0

    Consuming RSS from a file with a .PHP format

    I'm currently trying to consume an RSS from other sites. The problem is, the rss is in a .php format. (But it's actually XML, if you view the source)

    I'm trying to do it with

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Xml;
    
    @{
        //Get the XML from remote URL
        XmlDocument xml = new XmlDocument();
    
        //URL currently hardcoded - but you could use a macro param to pass in URL
        xml.Load("http://magister.jteti.ugm.ac.id/rss/penelitian.php");
    
        //Select the nodes we want to loop through
        XmlNodeList nodes = xml.SelectNodes("//item");
    
        //Traverse the entire XML nodes.
        foreach (XmlNode node in nodes)
        {
    
            //Get the value from the <title> node
            var title = node.SelectSingleNode("title").InnerText;
    
            //Get the value from the <description> node
            var description = node.SelectSingleNode("description").InnerText;
    
            <div>
            <h4>@title</h4>
            <p>@description</p>
    
            </div>
    
        } 
    }
    

    But it gives me errors.

    However, I've tried to change the rss url to other file (https://cyber.harvard.edu/rss/examples/sampleRss091.xml) which is in .xml format and it works fine

    Is it possible to consume the RSS if the provided file is in .php format? If yes, what is the possible way to do that? Thanks!

  • Sven Geusens 161 posts 869 karma points c-trib
    Sep 13, 2016 @ 15:46
    Sven Geusens
    100

    Hey

    It might have something to do with the fact that the xml rendered by the php file is not valid xml.

    Just view the source, copy the entire thing and paste it into any xml validator. eg: http://www.w3schools.com/xml/xml_validator.asp

    I have a feeling that the error you are getting is a XmlException error.

    Further documentation on XmlDocument.Load() might help you better understand how the function works: https://msdn.microsoft.com/en-us/library/875kz807(v=vs.110).aspx

    Hope this helps you out.

    Sven

Please Sign in or register to post replies

Write your reply to:

Draft