I have to read an XML file, that has no root element, to extract contained data. The XML has many elements like these:
<DocumentElement>
<LOG_x0020_ParityRate>
<DATE>12/09/2017 - 00:00</DATE>
<CHANNELNAME>ParityRate</CHANNELNAME>
<SQL>update THROOMDISP set ID_HOTEL = '104', ID_ROOM = '920', NUM = '3', MYDATA = '20171006' where id_hotel =104 and id_room ='920' and MYDATA ='20171006'</SQL>
<ID_HOTEL>104</ID_HOTEL>
<TYPEREQUEST>updateTHROOMDISP(OK)</TYPEREQUEST>
</LOG_x0020_ParityRate>
</DocumentElement><DocumentElement>
<LOG_x0020_ParityRate>
<DATE>12/09/2017 - 00:00</DATE>
<CHANNELNAME>ParityRate</CHANNELNAME>
<SQL>update THROOMDISP set ID_HOTEL = '105', ID_ROOM = '923', NUM = '1', MYDATA = '20171006' where id_hotel =105 and id_room ='923' and MYDATA ='20171006'</SQL>
<ID_HOTEL>105</ID_HOTEL>
<TYPEREQUEST>updateTHROOMDISP(OK)</TYPEREQUEST>
</LOG_x0020_ParityRate>
</DocumentElement><DocumentElement>
<LOG_x0020_ParityRate>
<DATE>12/09/2017 - 00:00</DATE>
<CHANNELNAME>ParityRate</CHANNELNAME>
<SQL>update THROOMDISP set ID_HOTEL = '104', ID_ROOM = '920', NUM = '3', MYDATA = '20171007' where id_hotel =104 and id_room ='920' and MYDATA ='20171007'</SQL>
<ID_HOTEL>104</ID_HOTEL>
<TYPEREQUEST>updateTHROOMDISP(OK)</TYPEREQUEST>
</LOG_x0020_ParityRate>
</DocumentElement><DocumentElement>
I tried to read it as a string, add manually opening and closing tags, and parse it like an XDocument, but it has also some bad formatted tags, like these
</DocumentElement>
<TYPEREQUEST>updateTHROOMPRICE(OK)</TYPEREQUEST>
Where these tags doesn't match any opening tags, and when I call XDocument.Parse
on the resulting string I have exceptions. The file has millions of rows, so I can't read it line by line, or the iteration will last for hours. How can I get rid of all these bad formatted tags and parse the document?