Charles W
Charles W

Reputation: 2292

Faster XmlReader Skip

I have an xml document in a hierarchical tree. I have a node with several million children under it.

When I run XmlReader.Skip() on that node, it takes several seconds to finish. Is there a faster way to skip all of the children and move to the next sibling?

Upvotes: 0

Views: 263

Answers (1)

Peter Duniho
Peter Duniho

Reputation: 70691

Is there a faster way to skip all of the children and move to the next sibling?

Without seeing your code, it's not possible to know for sure what might be done to speed it up.

But in general, no. If all you're really doing is calling the Skip() method, and you have ensured that the XmlReader is configured to do minimal processing on the XML, then the time it's taking is the time it's going to take.

The reader has to parse all the intermediate XML data to find the closing tag of the node you're processing, and with "several million children", that is a lot of data and parsing.

Now, that said: if you are willing to preprocess the data and index it, that would be a different story. But that'd be a lot more work. You can't just go resetting your stream position underneath the XmlReader object's state, so you'd need to do the XML parsing more manually. It all depends on how important it is for this part of your program to go fast. :)

(And it still would require indexing the XML, which itself would be time-consuming. But it's a one-time time-consuming operation).


As an aside, do note that XmlReader now has awaitable async methods. These won't make the I/O itself go faster, but if part of the problem here is time-consuming blocking I/O in the UI, using those would at least help keep the UI responsive.

You didn't mention any such problem in your question, and for all I know there is none. But I figured I might as well mention that, just in case.

Upvotes: 4

Related Questions