[thelist] PHP + XML + Array problem
Burhan Khalid
thelist at meidomus.com
Thu Mar 20 10:53:10 CST 2003
Hello List :
New to XML (but not new to PHP), and doing my first XML + PHP
project and ran into a snag.
I am reading an XML file that has this format :
<countries>
<country name="Afghanistan">
<state name="Afghanistan" url="AFG.xml" />
</country>
...
</countries>
I have managed to get PHP to make an array from this file that's
of this format (print_r() output) :
Array
(
[0] => Afghanistan
[1] => Array
(
[NAME] => Afghanistan
[URL] => AFG.xml
)
...
}
Now what I'm problems with is how to get the AFG.xml part if I
have "Afghanistan" as the key. Here is my non-working code :
while(list($key,$val) = each($arrayCountryList)) {
if (is_array($val)) {
while(list($country,$file) = each($val)) {
if ($country == "Afghanistan") {
$xml_CountryFile = $file;
}
}
}
}
Any help is much appreciated. This is a part of a xml class that
I am writing that pulls weather information. I have a feeling
the problem lies in the second while, but I don't know what to
check for, or how to fix it.
Along the same lines, can anyone tell me how to find a parent
node of a child in XML using PHP? Currently I am having to set a
flag for each tag, and sorting it out that way, and I'm hoping
someone has a better solution.
Thanks again.
--
Best regards,
Burhan
mailto:thelist at meidomus.com
More information about the thelist
mailing list