Alexey Rumin
Alexey Rumin

Reputation: 303

read part of very big xml document

I try to use linq to xml to read very big xml file (407 MB):

XDocument xdoc = XDocument.Load(adress);

(adress - is a path to file) But I get out of memory exception due to the fact (as I suppose) that collection becomes more than to 2GB. Xml file looks like that:

<lemmata>
<lemma id="4694" rev="4694"><l t="аддукторен"><g v="ADJS"/></l><f t="аддукторен"><g v="masc"/><g v="sing"/></f><f t="аддукторна"><g v="femn"/><g v="sing"/></f><f t="аддукторно"><g v="neut"/><g v="sing"/></f><f t="аддукторны"><g v="plur"/></f></lemma>
    <lemma id="4695" rev="4695"><l t="аддукторнее"><g v="COMP"/></l><f t="аддукторнее"></f><f t="аддукторней"><g v="V-ej"/></f><f t="поаддукторнее"><g v="Cmp2"/></f><f t="поаддукторней"><g v="Cmp2"/><g v="V-ej"/></f></lemma>
    <lemma id="4696" rev="4696"><l t="аддукция"><g v="NOUN"/><g v="inan"/><g v="femn"/></l><f t="аддукция"><g v="sing"/><g v="nomn"/></f><f t="аддукции"><g v="sing"/><g v="gent"/></f><f t="аддукции"><g v="sing"/><g v="datv"/></f><f t="аддукцию"><g v="sing"/><g v="accs"/></f><f t="аддукцией"><g v="sing"/><g v="ablt"/></f><f t="аддукциею"><g v="sing"/><g v="ablt"/><g v="V-ey"/></f><f t="аддукции"><g v="sing"/><g v="loct"/></f><f t="аддукции"><g v="plur"/><g v="nomn"/></f><f t="аддукций"><g v="plur"/><g v="gent"/></f><f t="аддукциям"><g v="plur"/><g v="datv"/></f><f t="аддукции"><g v="plur"/><g v="accs"/></f><f t="аддукциями"><g v="plur"/><g v="ablt"/></f><f t="аддукциях"><g v="plur"/><g v="loct"/></f></lemma>
<lemma>.....</lemma>
</lemmata>

So, there are many elements. Do I have an opportunity to read just a part of lemma elements in order collection of elements don't exceed the maximum size? Or there are other ways to read this file? Thank you

Upvotes: 0

Views: 81

Answers (1)

Simon Williams
Simon Williams

Reputation: 1046

Have a look at the XmlReader class. It allows you to forward read through the elements pretty quickly so that you can find the one you want, without pulling the whole file into memory.

Upvotes: 2

Related Questions