0

How can I get all "CommentingUser" ?

SimpleXMLElement Object
(
    [Timestamp] => 2011-08-01T08:24:55.384Z
    [Ack] => Success
    [Version] => 731
    [Build] => E731_INTL_BUNDLED_13551333_R1
    [FeedbackDetailArray] => SimpleXMLElement Object
        (
            [FeedbackDetail] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [CommentingUser] => kerryd53
                            [CommentingUserScore] => 124
                            [CommentText] => wonderful book
                            [CommentTime] => 2011-08-01T08:02:20.000Z
                            [CommentType] => Positive
                            [ItemID] => 120395264453
                            [Role] => Seller
                            [FeedbackID] => 540466592022
                            [TransactionID] => 740714734002
                            [OrderLineItemID] => 120395264453-740714734002
                            [ItemTitle] => NEW 30 Days to Taming Your Tongue Workbook - Pegues,...
                            [ItemPrice] => 5.99
                        )

                    [1] => SimpleXMLElement Object
                        (
                            [CommentingUser] => freddiec29
                            [CommentingUserScore] => 377
                            [CommentText] => fast shipping!
                            [CommentTime] => 2011-08-01T07:32:17.000Z
                            [CommentType] => Positive
                            [ItemID] => 150616990042
                            [Role] => Seller
                            [FeedbackID] => 540461424022
                            [TransactionID] => 621117682005
                            [OrderLineItemID] => 150616990042-621117682005
                            [ItemTitle] => NEW Rediform® Desk Pad/Wall Calendar, Chipboard, 21-3/4
                            [ItemPrice] => 5.99
                        )

                    [2] => SimpleXMLElement Object
                        (
                            [CommentingUser] => agustinagustin44
                            [CommentingUserScore] => 14
                            [CommentText] => great buy!
                            [CommentTime] => 2011-08-01T07:27:34.000Z
                            [CommentType] => Positive
                            [ItemID] => 150598601980
                            [Role] => Seller
                            [FeedbackID] => 540460633022
                            [TransactionID] => 619873682005
                            [OrderLineItemID] => 150598601980-619873682005
                            [ItemTitle] => NEW Gundam Seed Anime Legends Collection 1
                            [ItemPrice] => 31.99
                        )

                    [3] => SimpleXMLElement Object
                        (
                            [CommentingUser] => sollord
                            [CommentingUserScore] => 22
                            [CommentText] => Fast and accurate
                            [CommentTime] => 2011-08-01T07:20:00.000Z
                            [CommentType] => Positive
                            [ItemID] => 400222164187
                            [Role] => Seller
                            [FeedbackID] => 540459409022
                            [TransactionID] => 121359761027
                            [OrderLineItemID] => 400222164187-121359761027
                            [ItemTitle] => NEW Belkin PureAV® PF30 Home Theater Power Console
                            [ItemPrice] => 59.99
                        )



        )

)

I tried different tricks but they are not working .

  $xmlResponse = simplexml_load_string($output);
print_r($xmlResponse);
  $totalPages =  $xmlResponse->PaginationResult->TotalNumberOfPages;
echo "there are $totalPages pages";

  $feedback = $xmlResponse->FeedbackDetailArray;
print_r($feedback);

  foreach($feedback as $rows)
   {

 $username = $rows->FeedbackDetail;
 echo $username->CommentingUser;
}

The xml looks like this

<?xml version="1.0" encoding="UTF-8"?>
`<GetFeedbackResponse xmlns="urn:ebay:apis:eBLBaseComponents"><Timestamp>2011-08-01T08:39:00.631Z</Timestamp><Ack>Success</Ack><Version>731</Version>` `<Build>E731_INTL_BUNDLED_13551333_R1</Build><FeedbackDetailArray><FeedbackDetail><CommentingUser>amangi-machque</CommentingUser>`<CommentingUserScore>141</CommentingUserScore><CommentText>YAAAAAA!</CommentText><CommentTime>2011-08-01T08:38:16.000Z</CommentTime><CommentType>Positive</CommentType><ItemID>120420154018</ItemID><Role>Seller</Role><FeedbackID>540473547022</FeedbackID><TransactionID>744712455002</TransactionID><OrderLineItemID>120420154018-744712455002</OrderLineItemID><ItemTitle>NEW Keyspan High Speed USB Serial Adapter USA-19HS</ItemTitle><ItemPrice currencyID="USD">29.6</ItemPrice></FeedbackDetail><FeedbackDetail><CommentingUser>kerryd53</CommentingUser><CommentingUserScore>124</CommentingUserScore>`

4 Answers 4

2

It looks like you refer to the wrong element inside the xml object, try this:

$feedback = $xmlResponse->FeedbackDetailArray->FeedbackDetail;
foreach($feedback as $row)
Sign up to request clarification or add additional context in comments.

Comments

1

Try with:

foreach ($xmlResponse -> FeedbackDetailArray -> FeedbackDetail as $row)
{
    echo $row -> CommentingUser;
}

Comments

0

Well, if your XML looks something like this (I don't quite understand the structure from the above code):

<comments>
  <comment>
    <commentingUser>user1</commentingUser>
  </comment>
  <comment>
    <commentingUser>user2</commentingUser>
  </comment>
</coments>

you can read it like that:

foreach($xmlResponse->comment as $comment) {
   echo $comment->commentingUser;
}

Comments

0

If you're only gonna need the CommentingUser-elements, you can also do an xpath query to just fetch them.

foreach ($xmlResponse->xpath('CommentingUser') as $user) {
  echo $user;
}

http://www.php.net/manual/en/simplexmlelement.xpath.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.