Click to See Complete Forum and Search --> : stuck at XML and PHP


witold
09-30-2005, 10:14 AM
Hi,

I'm using HDOBJ class to parse xml.
http://www.phpclasses.org/browse/package/2566.html

Here is the structure of my xml file:

<transfer>
<AdvData ID="...." ExpDate="...">
<ContactData Firm="..." City="..." Country="...">
<Email Data="sample@email.com"/>
</ContactData>
<AdvCnt Requirements="..." JobTitle="..." Description="..."/>
</AdvData>
</transfer>

Basically, I don't have a problem with accessing the first
bunch of data, but it's getting on my nerves when I try
to retrieve Email Data and all attributes from the
AdvCnt node e.g. JobTitle.

Everything is ok with

PHP Code:
foreach ($obj->AdvData as $AdvData) {
foreach($AdvData->ContactData as $ContactData) {
echo $ContactData->get_attrib("City");
}
}

but, when I use

PHP Code:
foreach ($obj->AdvData as $AdvData) {
foreach($AdvData->AdvCnt as $AdvCnt) {
echo $AdvData->$AdvCnt->get_attrib("JobTitle");
}
}

I get an error message:

Warning: Invalid argument supplied for foreach()
pointing at foreach($AdvData->AdvCnt as $AdvCnt) line.

#####
Sorry for bothering you, but if you could help solve
my problem and show me a way to access these
nodes, I'd be grateful.

Regards,

Witold

Stephen Philbin
10-01-2005, 04:27 AM
<transfer>
<AdvData ID="...." ExpDate="...">
<ContactData Firm="..." City="..." Country="...">
<Email Data="sample@email.com"/>
</ContactData>
<AdvCnt Requirements="..." JobTitle="..." Description="..."/>
</AdvData>
</transfer>

It's because AdvCnt doesn't have any child elements. Contact data does, it has one child element of Email, but AdvCnt is an empty element there. Well, it might have a child text node of "\n", but that's it.