Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does XmlReader::next position the cursor when it returns false

Tags:

php

xml

xmlreader

If I have some XML, for example:

<library>
    <books>
        <book>
            <title>book #1</title>
        </book>
        <book>
            <title>book #2</title>
        </book>
    </books>
    <authors>
         <author>
             <name>author #1</name>
         </author>
         <author>
             <name>author #2</name>
         </author>
    </authors>
</library>

And having manoeuvred my cursor to the first book element I loop using:

do {
    //...
} while($xml->next("book"));

When my cursor is on the last book element and the next("book") is called, what happens to the cursor?

  • Does it stay on the last book element and return false.
  • Does it move to the </library> and return false.
  • Does it do something else?

I cannot figure out how to get the current cursor position to figure this out for myself.

like image 394
user2123475 Avatar asked Jun 28 '26 17:06

user2123475


1 Answers

Having looked at the source code of that function: http://lxr.php.net/xref/PHP_5_4/ext/xmlreader/php_xmlreader.c#821

It would appear that pointer moves to the end of the XML.

like image 79
user2123475 Avatar answered Jul 01 '26 12:07

user2123475



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!