...

View Full Version : How to access variable in xml



earni23
03-23-2010, 12:14 PM
Hi, I have the following xml-file (lang.xml):



<lang>
<langName>English</langName>
<months>
<month num = "1">Jan</month>
<month num = "2">Feb</month>
</months>
</lang>


To access the langName-variable I just write:


$xml = simplexml_load_file("lang.xml");
echo $xml->langName;


but how do I access the value "Feb" ($xml->months->month...), it must be possible to include the number "2" somehow in the php-code

Dormilich
03-23-2010, 12:30 PM
To access the langName-variable I just write:

the correct term here is node, XML is not a programming language, thus there are no variables.


but how do I access the value "Feb" ($xml->months->month...), it must be possible to include the number "2" somehow in the php-code

of course this is possible. you can access it by its list order number $xml->months->month[1] or if you explicitly test each list itemís num attribute.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum