Hoping someone could point me in the right direction on finding how to read given line number(s) from a giant xml file (50k+ lines)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since the lines in an XML file don’t typically have a fixed length, there’s no way to divine where the nth line in your file starts. You’ll have to start reading from the beginning and count lines until you find the one that you want.
If you’re going to access this file frequently, one thing you might want to do is to build an index for the file. Scan through the file and write the file offset of the beginning of each line into your index file. Since those offsets all have the same size, and since there’s one for every line, you can find the offset of the nth line of your data file by reading the nth offset from the index file.