Re: Simple XML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux