So I’m looking for a XML library that would be suitable for batch processing, I’d like to limit how many records are selected from XML file and an offset from where to start reading the records. I could not find anything relevant although I have went through github search, or maybe my search terms are not accurate enough, some libraries don’t even have a documentation so it’s really hard to tell right of the bat. But maybe some of you have already used ones that do just that and could share your findings.
Any help is appreciated
2
Answers
Take a look at
XMLReader
, which works more like a cursor reading through the XML, and which you can terminate and close whenever you want.For example :
Then
XMLReader allows you to optimize memory consumption mostly but it has a
XMLReader::next()
to iterate a list of sibling elements. Combined with some counters it should be pretty efficient but maintainable.After you moved to the right element you can read data using the XMLReader methods or expand it to DOM. The right solution/balance depends on how complex the structure of the "list item" elements is.