Correcting XmlReader problems using ReadToDescendant and/or ReadElementContentAsObject

后端 未结 1 1810
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 07:54

I\'m working on a mysterious bug in the usually very good open source project Excel Data Reader. It\'s skipping values reading from my particular OpenXML .xlsx spreadsheet.

相关标签:
1条回答
  • 2021-01-25 08:49

    It's fairly simple. As you can see from the output, the first time you're on the "B" line, you're positioned at the first 'v' Element. Then, you call ReadElementContentAsObject. That returns the text content of v, and "moves the reader past the end element tag." (of v). You are now pointing to a whitespace node if there is whitespace, or an EndElement node (of c) if there is not. Of course, your output doesn't print if it's whitespace. Either way, you then do a Read() and move on to the next element. In the case of the non-whitespace, you have lost the EndElement.

    The problem is much worse in other situtations. When you do a ReadElementContentAsObject of a c (call it c1), you then move on the next c (c2). Then you do a Read, moving to c3, and lose c2 for good.

    I'm not going to try to fix the real code. But it's clear what you need to worry about, moving the stream forward in more than one place. This is a common source of looping errors in general.

    0 讨论(0)
提交回复
热议问题