Reputation: 773
Is there a function to split an etree object set of child elements into multiple etree objects by index? For example, if my root node had say 400 children each with descendants, could I get 4 etree objects from each second of the file?
from lxml import etree as ET
tree = ET.parse('FileName.xml')
root = tree.getroot()
firstquarter = root.getchildren() #function to get 0-100 of the child nodes
secondquarter = root.getchildren() #function to get 101-200 of the child nodes
thirdquarter = root.getchildren() #function to get 201-300 of the child nodes
fourthquarter = root.getchildren() #function to get 301-400 of the child nodes
Upvotes: 2
Views: 172
Reputation: 24930
You should be able to do it simply with something like
firstquarter = root.getchildren()[0:100]
etc.
Upvotes: 1