You are here: Re: [PHP] Simple XML « PHP « IT news, forums, messages
Re: [PHP] Simple XML

Posted by Richard Lynch on 03/03/05 20:37

Uroš Gruber wrote:
> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
> epp-1.0.xsd">
>
> And then
>
> <resData>
> <domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
> xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd">
> <domain:cd>
> <domain:name avail="1">bar.com</domain:name>
> </domain:cd>
> <domain:cd>
> <domain:name avail="1">foo.com</domain:name>
> </domain:cd>
> </domain:chkData>
> </resData>
>
> But I cant get to this "cd" If I print_r complete response object it
> looks like it works, but then when I use
> resdata->chkData I got empty object.

I don't do XML, but some WILD GUESSES come to mind...

First, what's with the ":" in the tags?

I'm guessing that maybe you need to get to:
$resdata->domain:chkData
Except, of course, PHP doesn't allow a ":" in a member property name.

Maybe the ":" is some XML thing I just don't get, but maybe whomever wrote
your XML parser didn't get it either...

So what you've got is an object constructed with invalid properties that
you can't possibly access.

Maybe if you type-case that object to an array, and use:
$resData['domain:chkData']
you would get what you want...

If all else fails, scrap the fancy XML parser, and go with:

<?php
$xml = /* Load XML into a single long string */;
$resDatas = explode('<resData>', $xml);
while (list(, $resData) = each($resDatas)){
$chkDatas = explode('<domain:chkData>', $resData);
while (list(, $chkData) = each($resDatas)){
$cds = explode('<domain:cd>', $chkData);
while (list(, $cd) = each($cds)){
preg_match('<domain:name
avail="([01])">([a-zA-Z0-9\\.-]*)</domain:name>', $cd, $cddata);
echo "$cddata[2]: ", ($cddata[1] ? 'available' : 'taken'), "<br
/>\n";
}
}
}
?>

It's crude, but it's not like the XML here is all that complicated anyway.

XML bigots are probably ready to turn their flame-throwers on me. Oh well.

--
Like Music?
http://l-i-e.com/artists.htm

 

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

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