I have a xml file and I want to parse the author list in this XML file.
<AuthorList CompleteYN="Y">
<Author ValidYN="Y">
<LastName>Goyette-Desjardins</LastName>
<ForeName>Guillaume</ForeName>
<Initials>G</Initials>
<AffiliationInfo>
<Affiliation>University 1.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Auger</LastName>
<ForeName>Jean-Philippe</ForeName>
<Initials>JP</Initials>
<AffiliationInfo>
<Affiliation>University 2</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Xu</LastName>
<ForeName>Jianguo</ForeName>
<Initials>J</Initials>
<AffiliationInfo>
<Affiliation>University 3</Affiliation>
</AffiliationInfo>
</Author>
</AuthorList>
I used this code the get the author names which have Lastname
and Initial
but I got only the last author with my code (Xu J
).
$api_xml_url = "https://example.com&pid=3123133213&retmode=xml";
$xml = file_get_contents($api_xml_url);
preg_match_all("'<LastName>(.*?)</LastName>'si", $xml, $match);
foreach($match[1] as $LastName) {
$LastName = strip_tags($LastName);
}
preg_match_all("'<Initials>(.*?)</Initials>'si", $xml, $match);
foreach($match[1] as $Initials) {
$Initials = strip_tags($Initials);
}
$authors = $LastName.$Initials;
How to get the full author list (Goyette-Desjardins G; Auger JP; Xu J). Thank you very much