Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to loop SimpleXMLElement ? #1595

Closed
pwtitle opened this issue Oct 31, 2017 · 1 comment
Closed

How to loop SimpleXMLElement ? #1595

pwtitle opened this issue Oct 31, 2017 · 1 comment

Comments

@pwtitle
Copy link

pwtitle commented Oct 31, 2017

for ... in can't work with SimpleXMLElement?

My XML is :

<?xml version="1.0" encoding="UTF-8"?>
--
  | <Messages xmlns="http://mns.aliyuncs.com/doc/v1">
  | <Message>
  | <MessageId>52224710247175BA-1-15F72355F38-200000004</MessageId>
  | <MessageBodyMD5>D23B14C6CD9CA410B627D3C3C38BED34</MessageBodyMD5>
  | <MessageBody>["asdf","sadfasdf","2017-10-31 11:33:39"]</MessageBody>
  | <ReceiptHandle>1-ODU4OTkzNDU5Ni0xNTA5NjE0MzA5LTEtOA==</ReceiptHandle>
  | <EnqueueTime>1509449621304</EnqueueTime>
  | <FirstDequeueTime>1509608944846</FirstDequeueTime>
  | <NextVisibleTime>1509614309000</NextVisibleTime>
  | <DequeueCount>20</DequeueCount>
  | <Priority>8</Priority>
  | </Message>
  | <Message>
  | <MessageId>52224710247175BA-1-15F72358F0A-200000005</MessageId>
  | <MessageBodyMD5>0DC582A80C06D1C334899B104FFFDA5D</MessageBodyMD5>
  | <MessageBody>["asdf","sadfasdf","2017-10-31 11:33:51"]</MessageBody>
  | <ReceiptHandle>1-ODU4OTkzNDU5Ny0xNTA5NjE0MzA5LTEtOA==</ReceiptHandle>
  | <EnqueueTime>1509449633546</EnqueueTime>
  | <FirstDequeueTime>1509608952453</FirstDequeueTime>
  | <NextVisibleTime>1509614309000</NextVisibleTime>
  | <DequeueCount>17</DequeueCount>
  | <Priority>8</Priority>
  | </Message>
  | <Message>
  | <MessageId>52224710247175BA-1-15F7235936E-200000006</MessageId>
  | <MessageBodyMD5>C0CEFB762CE46988EDE0A0DF34243519</MessageBodyMD5>
  | <MessageBody>["asdf","sadfasdf","2017-10-31 11:33:52"]</MessageBody>
  | <ReceiptHandle>1-ODU4OTkzNDU5OC0xNTA5NjE0MzA5LTEtOA==</ReceiptHandle>
  | <EnqueueTime>1509449634670</EnqueueTime>
  | <FirstDequeueTime>1509608954367</FirstDequeueTime>
  | <NextVisibleTime>1509614309000</NextVisibleTime>
  | <DequeueCount>16</DequeueCount>
  | <Priority>8</Priority>
  | </Message>
  | <Message>
  | <MessageId>52224710247175BA-1-15F7235978C-200000007</MessageId>
  | <MessageBodyMD5>BE399129E2EA269C68EAAE815BE718AD</MessageBodyMD5>
  | <MessageBody>["asdf","sadfasdf","2017-10-31 11:33:53"]</MessageBody>
  | <ReceiptHandle>1-ODU4OTkzNDU5OS0xNTA5NjE0MzA5LTEtOA==</ReceiptHandle>
  | <EnqueueTime>1509449635724</EnqueueTime>
  | <FirstDequeueTime>1509608954799</FirstDequeueTime>
  | <NextVisibleTime>1509614309000</NextVisibleTime>
  | <DequeueCount>13</DequeueCount>
  | <Priority>8</Priority>
  | </Message>
  | </Messages>

when i use zephir language , the code is:

// zephir language code
.....
var xml = simplexml_load_string(xmlstring);
var k, v;
for v, v in xml {
    print_r(k);
    print_r(v);
}
....

the run time error is:

<b>Fatal error</b>:  Uncaught Exception: The argument is not initialized or iterable() in Test.zep:154

but It's work very good in PHP code

<?php
...
$xml = simplexml_load_string($xmlstring);
foreach ($xml as $item) {
    print_r($item);
}
...
  • who can help me ? thank you very much ?*
@sergeyklay sergeyklay self-assigned this Nov 3, 2017
@sergeyklay sergeyklay removed their assignment Dec 11, 2018
@dreamsxin dreamsxin mentioned this issue Feb 24, 2019
3 tasks
@sergeyklay
Copy link
Contributor

Fixed in the development branch. Feel free to open a new issue if the problem appears again. Thank you for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants