views:

79

answers:

1

I am using XMLReader to read a large XML file with about 1 million elements on the level I am reading from. However, I've calculated it will take over 10 seconds when I jump to -for instance- element 500.000 using XMLReader::next ([ string $localname ] ) or XMLReader::read ( void )

This is not very usable. Is there a faster way to do this?

+1  A: 

There isn't a fast way to do this. XML is inherently slow for random accesses, and there's no way around it.

The right thing to do is to think about your algorithm and decide why you're handling the data like this. Getting from one element to the next child or sibling element is cheap and fast. As long as your algorithm only has to go over the XML file once, you shouldn't incur much overhead. However, it sounds like you may be trying to access elements out-of-order, at arbitrary places in the structure. That will be slow as molasses no matter what reader you try to use.

JSBangs
I'll flag this as the right answer. Thank you Matti Virkkunen and JS Bangs.
Derk