You are here: SimpleXML + name spaces « All PHP « IT news, forums, messages
SimpleXML + name spaces

Posted by albanach on 10/13/71 11:34

Hi folks - hope someone can help me.

I have an XML file with some elements like those below

<core:District Id="AB01">
<core:Name>NORTH EAST</core:Name>
<core:Association Type="type1">VALUE 1a</core:Association>
<core:Association Type="type2">VALUE 1b</core:Association>
<core:Association Type="type3">VALUE 1c</core:Association>
</core:District>
<core:District Id="AB02">
<core:Name>NORTH WEST</core:Name>
<core:Association Type="type1">VALUE 2a</core:Association>
<core:Association Type="type2">VALUE 2b</core:Association>
<core:Association Type="type3">VALUE 2c</core:Association>
</core:District>

I'm trying to parse it using simplexml

I have:

$districts = $xmlfile->children($core);

foreach ($districts as $key => $value)
{
echo "Name = " . $value->Name . "\n";
echo "Region1 = " . $value->Association[0] . "\n";
echo "Region2 = " . $value->Association[1] . "\n";
echo "Region3 = " . $value->Association[2] . "\n";
}

This works fine, but I am unable to access the Id attribute in the
opening District element, i.e. AB01 or AB02.

Would anyone be able to suggest how I might get that value with
simplexml?

Many thanks,

Russell

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация