1

Im learning how to parse XML elements into an html document.

This takes a url with an xml, reads the elements but it ain't working...also I want to take it a bit further but I simply haven't been able to, how can I make it so I read the xml from a url? and use an xml element as filename to create an html document using a template?

////EDIT this is what I tried! /////EDIT/////EDIT/////EDIT/////EDIT/////EDIT/////EDIT

I tried this just for the sake of me knowing what Im doing(...apparently nothing haha) so I could echo if the information was right....

<?php

 $url = "http://your_blog.blogspot.com/feeds/posts/default?alt=rss";
 $xml = simplexml_load_file($url);
 print_r($xml);

?> 

Thank you for your time!

6
  • It seems like this is NOT your full code and you are prematurely ending your PHP script (got ?> anywhere?) You also forgot a ; after your URL. Commented Oct 24, 2013 at 17:24
  • @h2ooooooo tried a more coventional approach but it still ain't working..... I put the url on my browser and it works(copy/paste just in case) but still getting a blank page in return(Updated the code..once more) Commented Oct 24, 2013 at 17:34
  • Are you sure that blogspot allowed you to download data from other sources than your local server? Do you get an error? Commented Oct 24, 2013 at 17:35
  • @h2ooooooo I get nothing, just a blank page.... :/ Commented Oct 24, 2013 at 17:40
  • Is error_reporting(E_ALL); set? Commented Oct 24, 2013 at 17:41

1 Answer 1

1

Generally, "cross-domain" requests would be forbidden by web browsers, per the same origin security policy.

However, there is a mechanism that allows JavaScript on a web page to make XMLHttpRequests to another domain called Cross-origin resource sharing (CORS).

Read this about CORS: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Check this article out about RSS feeds: http://www.w3schools.com/php/php_ajax_rss_reader.asp

Sign up to request clarification or add additional context in comments.

5 Comments

Seems to me the xml document is in the same domain though.
No no no, it ain't, you see, I want to read an RSS feed, which is on xml. I want to read the xml, and create an html document from it using one of the elements inside....
@user1876553 You can't do that from another server unless you run it through your backend first (so instead of Client -> RSS, it'd be Client -> Server -> RSS). Check the link the elliospizzaman posted.
@h2ooooooo no, I think you guys are misunderstanding me. I read the rss(my own) feed, you get the information, right? Im trying to read it and create a file with the name of an element but that file is using a template. which has some other stuff...
@h2ooooooo changed my code for you guys to understand a little more of what Im trying to do

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.