Skip to content

Instantly share code, notes, and snippets.

@rsandrade
Last active February 6, 2017 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsandrade/df074b18fd09a55e70ed4c9cda656762 to your computer and use it in GitHub Desktop.
Save rsandrade/df074b18fd09a55e70ed4c9cda656762 to your computer and use it in GitHub Desktop.
<?php
$xml = simplexml_load_file('Nations.xml');
$a = 0;
foreach($xml->children() as $Placemark){
if($Placemark->name != '') {
echo $a . ' ' . $Placemark->name . "<br>";
foreach($Placemark->ExtendedData as $ExtendedData){
//var_dump($Data[0]['name']);
foreach($ExtendedData->children() as $Data){
var_dump($Data);
foreach($Data->children() as $key => $Name) {
var_dump($key);
}
}
echo '<p>';
}
}
$a++;
}
<?xml version='1.0' encoding='UTF-8'?>
<Document>
<description>Information about archives in greater Washington, DC metro area including surrounding areas of Maryland and Virginia | Created with http://batchgeo.com</description>
<Placemark>
<styleUrl>#0</styleUrl>
<name>Alan Mason Chesney Medical Archives</name> <ExtendedData>
<Data name='City and State'>
<value>Baltimore, MD</value>
</Data>
<Data name='Archives Foundation Date'>
<value>1978</value>
</Data>
<Data name='Featured Collection'>
<value>Overview of institutional records, personal paper collections, images, and material culture
</value>
</Data>
<Data name='Description'>
<value>The dedication of the Alan Mason Chesney Medical Archives was held on May 17, 1978 in conjunction with a special meeting of the Johns Hopkins Medical History Club. Funding from the Johns Hopkins Hospital, the health divisions of the Johns Hopkins University, and a grant from the Commonwealth Fund of New York enabled the development of the initial archival facility in the Turner Auditorium.
</value>
</Data>
<Data name='Category'>
<value>Academic</value>
</Data>
<Data name='Country'>
<value>United States</value>
</Data>
<Data name='Website'>
<value>http://www.medicalarchives.jhmi.edu/index.html</value>
</Data>
<Data name='Email'>
<value>archives@jhmi.edu</value>
</Data>
<Data name='Phone'>
<value>410-735-6800</value>
</Data>
</ExtendedData>
<address>5801 Smith Avenue, Suite 235 Baltimore MD 21209 United States</address>
<Point>
<coordinates>-76.654485762965,39.370046895349,0</coordinates>
</Point>
</Placemark>
<Placemark>
<styleUrl>#0</styleUrl>
<name>Albin O. Kuhn Library &amp; Gallery, Special Collections</name> <ExtendedData>
<Data name='City and State'>
<value>Blatimore, MD</value>
</Data>
<Data name='Archives Foundation Date'>
<value>1973</value>
</Data>
<Data name='Featured Collection'>
<value>Collection emphases: images demonstrating the social impact of photography or documenting the development of photography as an aesthetic medium.</value>
</Data>
<Data name='Description'>
<value>The Special Collections Department of the Albin O. Kuhn Library &amp; Gallery collects, houses, preserves, and makes accessible materials that are original, rare, unique, fragile, historical, and archival. Our diverse collections of rare books, photographs, manuscripts, archives and artifacts are available for research use by faculty, students, visiting scholars and the general public. All materials must be viewed on site in the reading room. A knowledgeable staff is available to assist researchers and to retrieve materials for study.
</value>
</Data>
<Data name='Category'>
<value>Academic</value>
</Data>
<Data name='Country'>
<value>United States</value>
</Data>
<Data name='Website'>
<value>http://aok2.lib.umbc.edu/specoll/</value>
</Data>
<Data name='Email'>
<value>aok@umbc.edu</value>
</Data>
<Data name='Phone'>
<value>410-455-2353</value>
</Data>
</ExtendedData>
<address>University of Maryland, Baltimore County
1000 Hilltop Circle Baltimore MD 21250 United States</address>
<Point>
<coordinates>-76.710729262141,39.256142356578,0</coordinates>
</Point>
</Placemark>
</Document>
@wgbn
Copy link

wgbn commented Feb 6, 2017

Eu fiz assim:

<?php

$xml = simplexml_load_file('Nations.xml');

$consolidado = array();

foreach ($xml->Placemark as $placemark) {
	foreach ($placemark->ExtendedData->Data as $data) {
		foreach($data->attributes() as $att)
			$consolidado["$att"] = "{$data->value[0]}";
	}
}

	print_r($consolidado);
?>

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