Skip to content

Instantly share code, notes, and snippets.

@MaheKarim
Created December 8, 2024 06:42
Show Gist options
  • Save MaheKarim/a402926cfe6dcb18df2756fa277f1cd5 to your computer and use it in GitHub Desktop.
Save MaheKarim/a402926cfe6dcb18df2756fa277f1cd5 to your computer and use it in GitHub Desktop.
UN Security Council XML File
<?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.";
}
@MaheKarim
Copy link
Author

Before Processing XML Data

XML Data RAW

After Processing It Via this PHP Code
Security Council

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment