0

my xml flie:

<item>
<title geoid="1198">District of Columbia</title>
<description cong_dist="Delegate District (at Large) 98">DC - Delegate District (at Large) 98 <br/> No of Incidents: 1436</description>
<latitude>38.8933115</latitude>
<longitude>-77.0146475</longitude>
<georss:polygon>38.934311 -77.1199 38.939834989364 -77.112868886998 38.94641 -77.1045 38.94891 -77.1007 38.95651 -77.0915 38.960871062931 -77.085827416011 38.967245703105 -77.077535703105 38.971616050926 -77.07185104194 38.98511 -77.054299 38.986557824794 -77.052373393024 38.99511 -77.040999 38.99171 -77.036299 38.98423067065 -77.026499658425 38.977828623846 -76.909395 38.895811472659 -76.913155644266 38.904084963804 -76.923528686655 38.904209815545 -76.923685221832 38.910455906543 -76.931516373827 38.913311 -76.935096 38.918592133391 -76.941928356721 38.930758817183 -76.957668751373 38.93511031877 -76.963298416241 38.946183221387 -76.977623754198 38.951906165093 -76.985027693844 38.95742281319 -76.992164742828 38.961159688178 -76.99699924729 38.96541 -77.002498 38.97011 -77.008298 38.97441 -77.013798 38.97591 -77.015598 38.977828623846 -77.018111761535 38.98423067065 -77.026499658425 38.99171 -77.036299 38.99511 -77.040999 38.986557824794 -77.052373393024 38.98511 -77.054299 38.971616050926 -77.07185104194 38.967245703105 -77.077535703105 38.960871062931 -77.085827416011 38.95651 -77.0915 38.94891 -77.1007 38.94641 -77.1045 38.939834989364 -77.112868886998 38.934311 -77.1199</georss:polygon>
</item>

i stored this values in dc.xmlfile

how to get all the values in a variable. for example tag values is stored in $lat variable in php.

how to get this values i need your kind help...,

2 Answers 2

2

Try this out

<?php
$string = <<<XML
<?xml version='1.0'?>
<item>
<title geoid="1198">District of Columbia</title>
<description cong_dist="Delegate District (at Large) 98">DC - Delegate District (at Large) 98 <br/> No of Incidents: 1436</description>
<latitude>38.8933115</latitude>
<longitude>-77.0146475</longitude>
<georss:polygon>38.934311 -77.1199 38.939834989364 -77.112868886998 38.94641 -77.1045 38.94891 -77.1007 38.95651 -77.0915 38.960871062931 -77.085827416011 38.967245703105 -77.077535703105 38.971616050926 -77.07185104194 38.98511 -77.054299 38.986557824794 -77.052373393024 38.99511 -77.040999 38.99171 -77.036299 38.98423067065 -77.026499658425 38.977828623846 -76.909395 38.895811472659 -76.913155644266 38.904084963804 -76.923528686655 38.904209815545 -76.923685221832 38.910455906543 -76.931516373827 38.913311 -76.935096 38.918592133391 -76.941928356721 38.930758817183 -76.957668751373 38.93511031877 -76.963298416241 38.946183221387 -76.977623754198 38.951906165093 -76.985027693844 38.95742281319 -76.992164742828 38.961159688178 -76.99699924729 38.96541 -77.002498 38.97011 -77.008298 38.97441 -77.013798 38.97591 -77.015598 38.977828623846 -77.018111761535 38.98423067065 -77.026499658425 38.99171 -77.036299 38.99511 -77.040999 38.986557824794 -77.052373393024 38.98511 -77.054299 38.971616050926 -77.07185104194 38.967245703105 -77.077535703105 38.960871062931 -77.085827416011 38.95651 -77.0915 38.94891 -77.1007 38.94641 -77.1045 38.939834989364 -77.112868886998 38.934311 -77.1199</georss:polygon>
</item>
XML;

$xml = simplexml_load_string($string);
$title = $xml->title;
print_r($title);
?>
Sign up to request clarification or add additional context in comments.

1 Comment

it is showing an error in $title = $xml->title; this line sir..,
1

see this screen shot there is no error at all what you are sayingenter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.