10 Replies - 2293 Views - Last Post: 07 May 2012 - 08:53 AM Rate Topic: -----

#1 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 05:43 PM

Hello

I am working on my graduation project and I have a critical problem with my php code and I am just beginner in php coding.

I am reading from text file IDs of papers and want to link between the ID that I read form my text file and the XML file so that is my code :
<?php
$file = fopen("abstract/Temp_id.txt","r");
$ids;
while(!feof($file))
{
    $ids = fgets($file);
    
    $xml = simplexml_load_file("abstract/$ids");//abstract is the folder which I save my files and //read from it
    
    $title="bibliomisc =".$xml->articleinfo[0]->bibliomisc;

    echo $title;
    echo"<a href=abstract/$ids title='Click to open :)/>'>$ids</a>";
}
fclose($file); 
?>


BUT I worked on openssl and it is working if I give it the name of ID e.g.
$xml = simplexml_load_file("abstract/8104317");//it is working but if I read from file I got that error



Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "8104317.xml " in /opt/lampp/htdocs/GP/xml_test.php on line 9

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12
bibliomisc =
8104317.xml
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "" in /opt/lampp/htdocs/GP/xml_test.php on line 9

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12
bibliomisc =


help please :) thanks

This post has been edited by Atli: 06 May 2012 - 06:07 PM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: error "failed to load external entity'"Trying to get prope

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 06:21 PM

Hey.

What, exactly, is the name of the files? Do they include the .xml extension? I ask because in your last line, the one you say works, you don't include the extension, but in the error you posted it does seem to be included.


Also, there may be another reason for this. If you read the manual entry for the fgets function, you find this:

php.net/fgets said:

Reading ends when length - 1 bytes have been read, on a newline (which is included in the return value), or on EOF (whichever comes first).

So, when you read in the line, the new-line character is included. This will then also be included in the file name. I'm actually not sure if SimpleXML trims it away or if tries to read it as a part of the file name. The error suggests the latter. If you look closely, the filename in the error messages is: "8104317.xml ", which includes a white-space at the end.

In any case, you should not take the chance. Use the trim() function on the return value of fgets() before trying to use it as a part of the file name.

You would also do well to verify that the file you are attempting to read actually exists before you try to read it. For that the file_exists function comes in handy.
Was This Post Helpful? 1
  • +
  • -

#3 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 06:45 PM

I am so happy for your answer.

simply I am using a perl script to download scientific papers from pubmed and the script downloads the Temp_id.txt and the abstract of the paper I read from this .txt file and hyperlink to the file for example if the .txt file contains 12923 and the abstract 12923 exist so it links to it.
I tried to hyperlink this ID as shown in my code but I failed to do this by the way I tried to change the extension to .xml but it doesn't work also.
If you have a solution or another idea to link what I read from .txt to perform xml operations on it please answer

thanks
Was This Post Helpful? 0
  • +
  • -

#4 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 06:51 PM

please give me an example of how to use trim function
thanks
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2993
  • View blog
  • Posts: 10,342
  • Joined: 08-August 08

Re: error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 07:10 PM

This is your graduation project? You should have bookmarked this site long ago.
Was This Post Helpful? 0
  • +
  • -

#6 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 07:27 PM

I make it with trim
    
$ids = fgets($file);
    
//$url = "$ids";
trim($ids);
$xml = simplexml_load_file("abstract/$ids");



but still no results the same error
Was This Post Helpful? 0
  • +
  • -

#7 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: error "failed to load external entity'"Trying to get prope

Posted 06 May 2012 - 11:14 PM

You need to look closer at the documentation for the trim function (the link I posted earlier). The function, like most PHP functions, does not modify the input variable but rather returns the modified value. In other words, the trimmed value will be returned while the original variable is left untouched.
Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: error "failed to load external entity'"Trying to get prope

Posted 07 May 2012 - 03:13 AM

Not to mention, if $ids is actually a list of IDs, it's not going to work.

Shouldn't you know the language -- and some sense of programming logic -- prior to doing a "graduation project"?
Was This Post Helpful? 0
  • +
  • -

#9 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: error "failed to load external entity'"Trying to get prope

Posted 07 May 2012 - 08:37 AM

View PostAtli, on 06 May 2012 - 11:14 PM, said:

You need to look closer at the documentation for the trim function (the link I posted earlier). The function, like most PHP functions, does not modify the input variable but rather returns the modified value. In other words, the trimmed value will be returned while the original variable is left untouched.

okay I looked at the link you posted but please :) I am not familiar with the php so if you can write a piece of code that make this code work with trim function because I tried but I failed ??

View PostJackOfAllTrades, on 07 May 2012 - 03:13 AM, said:

Not to mention, if $ids is actually a list of IDs, it's not going to work.

Shouldn't you know the language -- and some sense of programming logic -- prior to doing a "graduation project"?

thanks for you replay

but I have to work with php to make a new website for our graduation project so I you have any idea for this problem please say it :) and as I saied I am NOT familiar with php and just beginner
Was This Post Helpful? 0
  • +
  • -

#10 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: error "failed to load external entity'"Trying to get prope

Posted 07 May 2012 - 08:47 AM

View PostAtli, on 06 May 2012 - 11:14 PM, said:

You need to look closer at the documentation for the trim function (the link I posted earlier). The function, like most PHP functions, does not modify the input variable but rather returns the modified value. In other words, the trimmed value will be returned while the original variable is left untouched.

thanks for you helo really I apperciate this for you thanks :)

I used the following modifications with trim function
$trimmed = trim($ids, " \n");
    $xml = simplexml_load_file("abstract/$trimmed");


and it worked BUUUUUT I have a lot of warnings

Warning: simplexml_load_file() [function.simplexml-load-file]: abstract/:1: parser error : Document is empty in /opt/lampp/htdocs/GP/xml_test.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: in /opt/lampp/htdocs/GP/xml_test.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /opt/lampp/htdocs/GP/xml_test.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: abstract/:1: parser error : Start tag expected, '<' not found in /opt/lampp/htdocs/GP/xml_test.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: in /opt/lampp/htdocs/GP/xml_test.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /opt/lampp/htdocs/GP/xml_test.php on line 12

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 18

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 18

and please tell me how to make my file doesn't read the last line
Was This Post Helpful? 0
  • +
  • -

#11 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: error "failed to load external entity'"Trying to get prope

Posted 07 May 2012 - 08:53 AM

this problem because it reads the last line of my file so please tell me how to make this code doesn't read the last line.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1