Created
December 8, 2024 06:42
-
-
Save MaheKarim/a402926cfe6dcb18df2756fa277f1cd5 to your computer and use it in GitHub Desktop.
UN Security Council XML File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// URL of the XML file | |
$url = 'https://scsanctions.un.org/resources/xml/en/consolidated.xml'; | |
// Load the XML file into a SimpleXMLElement | |
$xml = simplexml_load_file($url); | |
// Check if loading was successful | |
if ($xml === false) { | |
echo "Failed to load XML.\n"; | |
foreach (libxml_get_errors() as $error) { | |
echo $error->message . "\n"; | |
} | |
exit; | |
} | |
// The root element should be something like <CONSOLIDATED_LIST>. Let’s explore the structure. | |
// For example, we can look into the INDIVIDUALS section. | |
if (isset($xml->INDIVIDUALS->INDIVIDUAL)) { | |
foreach ($xml->INDIVIDUALS->INDIVIDUAL as $individual) { | |
// Each INDIVIDUAL might have elements like FIRST_NAME, SECOND_NAME, etc. | |
$firstName = (string)$individual->FIRST_NAME; | |
$secondName = (string)$individual->SECOND_NAME; | |
$thirdName = (string)$individual->THIRD_NAME; | |
// Print out some details | |
echo "Name: " . trim($firstName . ' ' . $secondName . ' ' . $thirdName) . "<br/>"; | |
// You can also inspect other tags like COMMENTS1, DESIGNATION, DATE_OF_BIRTH, etc. | |
if (!empty($individual->COMMENTS1)) { | |
echo "Comments: " . (string)$individual->COMMENTS1 . "<br/>"; | |
} | |
// If there are NATIONALITY entries, for example: | |
if (isset($individual->NATIONALITY)) { | |
foreach ($individual->NATIONALITY as $nationality) { | |
echo "Nationality: " . (string)$nationality->VALUE . "<br/>"; | |
} | |
} | |
echo "<hr/>"; | |
} | |
} else { | |
echo "No INDIVIDUAL data found in the XML."; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before Processing XML Data
After Processing It Via this PHP Code
