Re: Simple XML

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

 



Richard Lynch wrote:
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

out of interest what does print_r() actually output? better yet what does var_dump() actually output? (i.e. post the output please)

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?

that'll be designating namespaces. although I never knew you could stipulate as namespace in a tag that actually references/loads said namespace:

<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">

BTW: I remember reading about problems with namespace when using simpleXML (actually I remember
reading that namespaces where not supported) - this information maybe completely wrong (or
just out of date), anyway check the php-internals archives for more info on that


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.

I'm all out of gas, oh hang on I don't even like XML that much :-) - with php4 I found XML a bit nightmarish, and all that namespace stuff can, well, really screw up your day... I think Uroš knows that already :-/



-- 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