Jump to content

SimpleXML that won't be simple.


10,000 BC Man

Recommended Posts

Hello,

 

I've been fiddling with this for a while. I can get DOM to output all the "name" nodes (for example), but I'm new to PHP and, good as DOM is, I realy need to stick with SimpleXML.

 

XML file ...

 

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>HiRISE Footprints</name>

<Snippet>
PDS-released information.
</Snippet>
<description>
<p>
These data are from the 
<a href='http://hirise.lpl.arizona.edu/'>High Resolution Imaging Science Experiment (HiRISE)</a> on board the 
<a href='http://mars.jpl.nasa.gov/mro/'>Mars Reconnaissance Orbiter (MRO)</a> as released through the
<a href='http://pds-imaging.jpl.nasa.gov/Missions/MRO_mission.html'>Planetary Data System (PDS)</a>.
</p>

<p>
This KML file was built on Mon Mar 24 04:10:07 2008.  For more information, contact Ross A. Beyer.
</p>
</description>
<open>1</open>
<Style id="HiRISEPoly_normal">
	<LineStyle>
		<width>1.5</width>
		<color>ff0000ff</color>
	</LineStyle>
	<PolyStyle>
		<fill>0</fill>
	</PolyStyle>
	<IconStyle>
		<Icon>
			<href>HiRISE_icon.png</href>
		</Icon>
	</IconStyle>
	<BalloonStyle>
		<bgColor>00000000</bgColor>
		<textColor>ffffffff</textColor>
	</BalloonStyle>
</Style>
<Style id="HiRISEPoly_highlight">
	<LineStyle>
		<width>3</width>
		<color>ff0000ff</color>
	</LineStyle>
	<PolyStyle>
		<fill>0</fill>
	</PolyStyle>
	<IconStyle>
		<Icon>
			<href>HiRISE_icon_highlight.png</href>
		</Icon>
	</IconStyle>
	<BalloonStyle>
		<bgColor>00000000</bgColor>
		<textColor>ffffffff</textColor>
	</BalloonStyle>
</Style>
<StyleMap id="HiRISEPoly">
	<Pair>
		<key>normal</key>
		<styleUrl>#HiRISEPoly_normal</styleUrl>
	</Pair>
	<Pair>
		<key>highlight</key>
		<styleUrl>#HiRISEPoly_highlight</styleUrl>
	</Pair>
</StyleMap>


<Placemark>
<name>AEB_000001_0000</name>
<styleUrl>#HiRISEPoly</styleUrl>
<description>
<p>Bosporos Planum region</p>
<p>
<a href='http://hirise.lpl.arizona.edu/AEB_000001_0000'><font color="#00FFFF">HiRISE Observation Web page</font></a>
</p>
<div>
<a href='http://hirise.lpl.arizona.edu'><img src="HiRISE_logo.png" /></a>
</div>
</description>
<MultiGeometry>
	<Point>
		<coordinates>-54.931,-33.6515</coordinates>
	</Point>
	<Polygon>
		<tessellate>1</tessellate>
		<outerBoundaryIs>
			<LinearRing>
				<coordinates>
-55.39,-33.3967
-54.382,-33.515
-54.474,-33.907
-55.476,-33.7908
-55.39,-33.3967
				</coordinates>
			</LinearRing>
		</outerBoundaryIs>
	</Polygon>
</MultiGeometry>
</Placemark>

<Placemark>
<name>AEB_000001_0050</name>
<styleUrl>#HiRISEPoly</styleUrl>
<description>
<p>Cratered plains near Bosporos Rupes</p>
<p>
<a href='http://hirise.lpl.arizona.edu/AEB_000001_0050'><font color="#00FFFF">HiRISE Observation Web page</font></a>
</p>
<div>
<a href='http://hirise.lpl.arizona.edu'><img src="HiRISE_logo.png" /></a>
</div>
</description>
<MultiGeometry>
	<Point>
		<coordinates>-56.509,-40.6371</coordinates>
	</Point>
	<Polygon>
		<tessellate>1</tessellate>
		<outerBoundaryIs>
			<LinearRing>
				<coordinates>
-56.939,-40.497
-56.035,-40.5908
-56.078,-40.7775
-56.98,-40.6844
-56.939,-40.497
				</coordinates>
			</LinearRing>
		</outerBoundaryIs>
	</Polygon>
</MultiGeometry>
</Placemark>

<Placemark>
<name>AEB_000001_0100</name>
<styleUrl>#HiRISEPoly</styleUrl>
<description>
<p>Degraded crater near Halley Crater</p>
<p>
<a href='http://hirise.lpl.arizona.edu/AEB_000001_0100'><font color="#00FFFF">HiRISE Observation Web page</font></a>
</p>
<div>
<a href='http://hirise.lpl.arizona.edu'><img src="HiRISE_logo.png" /></a>
</div>
</description>
<MultiGeometry>
	<Point>
		<coordinates>-58.002,-47.1389</coordinates>
	</Point>
	<Polygon>
		<tessellate>1</tessellate>
		<outerBoundaryIs>
			<LinearRing>
				<coordinates>
-58.405,-47.0341
-57.566,-47.1121
-57.601,-47.2536
-58.438,-47.1761
-58.405,-47.0341
				</coordinates>
			</LinearRing>
		</outerBoundaryIs>
	</Polygon>
</MultiGeometry>
</Placemark>
</Document>
</kml>

 

This outputs nothing ....

 

<?php

if (file_exists('hirise_snippet.xml')) {
$xml = simplexml_load_file('hirise_snippet.xml');
} else {
exit('Failed to open hirise_snippet.xml');
}

foreach ($xml->Placemark as $placemark) {
   echo $placemark->name, '<br />';
}

?>

 

As does this using XPath...

 

<?php

if (file_exists('hirise_snippet.xml')) {
$xml = simplexml_load_file('hirise_snippet.xml');
} else {
exit('Failed to open hirise_snippet.xml');
}

foreach ($xml->xpath('//Placemark') as $placemark) {
   echo $placemark->name, '<br />';
}

?>

 

They are both based on examples from php.net. At first I thought it was because I'm parsing Google KML, and yet I can get DOM to output all the name nodes ! I'd like to use SimpleXML if I can ... because it's simple.

 

BC Man

 

 

Link to comment
https://forums.phpfreaks.com/topic/100781-simplexml-that-wont-be-simple/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.