TheNetImp (thenetimp) wrote in php_dev,
TheNetImp
thenetimp
php_dev

SimpleXMLElement Question.

I am connecting to Amazon's S3 web service. I've created 2 buckets, and am now writing a function to get back the list of buckets from S3, and am having problems parsing the XML with simple XML.

I've got down to the bucket Node in a foreach loop as $bucketObj in the XML this Node had "Name" and "CreationDate" as XML nodes.

$bucketObj->Name;
$bucketObj->CreationDate;

The problem is when I call them instead of getting a "string" variable, I have a "SimpleXMLElement" If I var dump Name it looks like

    object(SimpleXMLElement)#17 (1) {
      [0]=>
      string(13) "JamesTest1234"
    }


How do I get access to [0] I've tried all kinds of things. If it was ['0'] I'd know how to get it, but in this case when I try $bucketObj->Name->0 it fails I've also tried $bucketObj->Name[0].

I'm really confused. I've used SimpleXML before and hadn't had any kinds of issues like this, so any suggestions would be greatly appreaciated.

This is the XML I receive with a little modified info:
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Owner>
        <ID>amazon key data</ID>
        <DisplayName>amazon</DisplayName>
    </Owner>
    <Buckets>
        <Bucket>
            <Name>JamesTest1234</Name>
            <CreationDate>2007-04-29T01:08:47.000Z</CreationDate>
        </Bucket>
        <Bucket>
            <Name>JamesTest12345</Name>
            <CreationDate>2007-04-29T01:10:47.000Z</CreationDate>
        </Bucket>
    </Buckets>
</ListAllMyBucketsResult>
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 2 comments