1

Im using the following to obtain the contents of an xml file:

<?php 

parse_str($_SERVER['QUERY_STRING']);

$file_loc="https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=".$search.";

$raw_xml = simplexml_load_file($file_loc) or die("Error: Cannot create object");

$xml = simplexml_load_string('<xml_container>'.$raw_xml.'</xml_container>');

$xml = json_decode( json_encode($xml) , 1);

echo "<br> print_r:";
print_r($xml);

echo "<br> vardump:";
var_dump($xml);


?>

An example using 'ACTN3' as the search term, i.e.

https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=ACTN3

should return:

<eSearchResult>
<Count>248</Count>
<RetMax>20</RetMax>
<RetStart>0</RetStart>
<IdList>
<Id>28195972</Id>
<Id>28177749</Id>
<Id>28177711</Id>
<Id>28154975</Id>
<Id>28139640</Id>
<Id>27966742</Id>
<Id>27913923</Id>
<Id>27861536</Id>
<Id>27821924</Id>
<Id>27819725</Id>
<Id>27798356</Id>
<Id>27747845</Id>
<Id>27601773</Id>
<Id>27584214</Id>
<Id>27508148</Id>
<Id>27442335</Id>
<Id>27361258</Id>
<Id>27294501</Id>
<Id>27274666</Id>
<Id>27188902</Id>
</IdList>
<TranslationSet/>
<TranslationStack>
<TermSet>
<Term>ACTN3[All Fields]</Term>
<Field>All Fields</Field>
<Count>248</Count>
<Explode>N</Explode>
</TermSet>
<OP>GROUP</OP>
</TranslationStack>
<QueryTranslation>ACTN3[All Fields]</QueryTranslation>
</eSearchResult>

Instead my code returns

print_r:Array ( ) 
vardump:array(0) { }

How can I retrieve the XML (e.g. from https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=ACTN3) and print it?

1 Answer 1

1

Yes it return the xml but the problem is you are appending string to object.Try below:

$file_loc="https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=ACTN3";

$raw_xml = simplexml_load_file($file_loc) or die("Error: Cannot create object");
echo "<pre>";
print_r($raw_xml);
Sign up to request clarification or add additional context in comments.

Comments

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.