Jump to content

Parsing XML NOT Working?


aristide

Recommended Posts

I need your help!


I need to read this xml file... but the problem is that it's not working!


This is the XML



<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Video</title>
<media:content url="http://videourl.com/" type="video/x-flv" duration="5128"/>
</item>
</channel>
</rss>

And this is my code:



<?php
$xml=simplexml_load_file("http://videourl.com/etc/");
echo $xml->getName() . "<media:content url=";

foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "";
}

?>

And it's not working! It's not working because nothing gets echoed, or printed! Does anyone spot the error?


Could it be because the URL of the xml file does not end in with .xml? or is it because this is MRSS xml?


 


thanks!


Edited by aristide
Link to comment
Share on other sites

well i made a test file with the xml contents under a different extension and it loads fine, and it also reads fine. using the following:

 

 

<?php
 
$xml=simplexml_load_file("etc/test.txt");
echo "<pre>";print_r($xml);echo "</pre>";
 
echo "<b>name: ".$xml->getName(). "</b><br/>";
 
foreach($xml->children() as $child)
{
  echo "<b>child: ".$child->getName()."</b><br/>";
  echo "<pre>";print_r($child); echo "</pre>";
}
 
?>
 

output:

 

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 2.0
        )

    [channel] => SimpleXMLElement Object
        (
            [item] => SimpleXMLElement Object
                (
                    [title] => Video
                )

        )

)
name: rss
child: channel
SimpleXMLElement Object
(
    [item] => SimpleXMLElement Object
        (
            [title] => Video
        )

)
so uh.. problem is probably with whatever the server is responding with, for the url you are using. Try just using file_get_contents and echoing that out to see if you are getting what you expect.
Link to comment
Share on other sites

Ok i'm going to try. But the thing I'm trying to do is get the URL value in the XML file, not to display the whole file.

 

EDIT: Tried file get contents but it didn't work... I think the website doesn't allow me to read the files?

Edited by aristide
Link to comment
Share on other sites

okay well I just used printing out the whole file as an example, roughly same as what you did. Getting a specific value within the file is a separate issue. You first need to sort out getting the file to load. The purpose of using file_get_contents is it's a really basic way of just requesting the file and getting the contents, not worrying about parsing it. If it isn't returning what you expect, then it might provide clues to next step.

Link to comment
Share on other sites

You are right, the problem is that it's not printing the file at all. Would it help if I gave you the link?

 

here it is:

http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0

And the thing i'm trying to get is the url! is the extension (or the lack of it) blocking me?

Edited by aristide
Link to comment
Share on other sites

no, it's not the extension.. php doesn't really care about extensions when it comes to this. Are you sure that's the extent of your code? using file_get_contents() on that url I get the xml contents, and doing it via simplexml works for me (as an xml text to just dump file):

 

<?php
$file = "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0";
$xml=simplexml_load_file($file);
echo "<pre>";print_r($xml);echo "</pre>";
?> 
I get:

 

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 2.0
        )

    [channel] => SimpleXMLElement Object
        (
            [item] => SimpleXMLElement Object
                (
                    [title] => Video
                )

        )

)
maybe the server is blocking your sever specifically or something...
Link to comment
Share on other sites

try

$xml=simplexml_load_file("http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0");

$xml->registerXPathNamespace("media", current($xml->getNamespaces()));

foreach ($xml->xpath('//media:content') as $c) {
    echo $c['url'] . '<br>';
    echo $c['type'] . '<br>';
    echo $c['duration'] . '<br>';
    
}
Link to comment
Share on other sites

@barand

Thanks for the code but its givin me an error:

 

Warning: simplexml_load_file(http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0) [function.simplexml-load-file]: failed to open stream: Connection timed out in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22

 

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0" in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22

 

Fatal error: Call to a member function registerXPathNamespace() on a non-object in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 24

Link to comment
Share on other sites

no, it's not the extension.. php doesn't really care about extensions when it comes to this. Are you sure that's the extent of your code? using file_get_contents() on that url I get the xml contents, and doing it via simplexml works for me (as an xml text to just dump file):

 

 

<?php
$file = "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0";
$xml=simplexml_load_file($file);
echo "<pre>";print_r($xml);echo "</pre>";
?> 
 
I get:

 

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 2.0
        )

    [channel] => SimpleXMLElement Object
        (
            [item] => SimpleXMLElement Object
                (
                    [title] => Video
                )

        )

)
maybe the server is blocking your sever specifically or something...
It must be something... Im pretty sure that my server isnt blocked. I get the result you get aswell, but the thing i need is the url!
Link to comment
Share on other sites

@barand

Thanks for the code but its givin me an error:

 

Warning: simplexml_load_file(http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0) [function.simplexml-load-file]: failed to open stream: Connection timed out in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22

 

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://www.putlocker.com/get_file.php?stream=WyJSVEU0TnpGRE9ERXlOemt6UTBRek5Eb3hNemc1TlRJMU16VTRMalk1TnpNNk5EVTBZVFpoWTJaak0yWmxOVEJtTVRjNU5UZGhORGxqTWpKbFl6Z3hZbUZtT0dSaU1qVmpPQT09IiwicmVnIl0" in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 22

 

Fatal error: Call to a member function registerXPathNamespace() on a non-object in /home/vol3_2/byethost9.com/b9_14135796/htdocs/test/test.php on line 24

When I ran it it gave

http://cdn.putlocker.com/r1KH3Z%2FaMY6kLQ9Y4nVxYpvXrk1%2FQyNvy7xPy8vQTltYliWCdpShxmSPnVzNmP5VlwgLPSYQ%2FddAb5kJ5ZFi3mY0R4gfIY2P69RYRz64ox67Z4LwcyYyZpbQM2FaWb6Or7RgBzqiU1bacFc%2BUyjR95aQgfTpPENEM1NkokFtDaP6oxoBy5mLYlHYbEvIYKwka9qymnoJuwbjKg83fnPX2z7hS6NXWxpudU1NBTWGfSM%3D/aec5ea42616804a307c016b03f6a3e45.flv/aec5ea42616804a307c016b03f6a3e45.flv
video/x-flv
5049
Link to comment
Share on other sites

It must be something... Im pretty sure that my server isnt blocked. I get the result you get aswell, but the thing i need is the url!

 

I think you need to be more clear, if you get his results then what is the problem? The next step is grabbing the URL, we need to confirm that the xml object returns the content as you mention, so we can move on to getting the URL.

Edited by GetFreaky
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.