Description
Type of issue
Other (describe below)
Description
Link to the doc: https://learn.microsoft.com/en-us/dotnet/standard/linq/stream-xml-fragments-xmlreader?source=docs#example-create-a-custom-axis-method
That sample code only returns expected results, if the input XML contains formatting (newlines).
Remove newlines from it - and the code skips first two Child
elements and only prints ccc
.
In more details, the issue happens because XElement.ReadFrom()
reads the current element and positions the reader at the next element. When the XML has formatting, that next element will be of type Whitespace
or smth - and everything works. But without formatting that next element will be the next Child
element. Then the reader.Read()
happens, which moves the reader to yet another next element. Hence the <Child Key=""02"">
tag simply gets skipped.
Page URL
https://learn.microsoft.com/en-us/dotnet/standard/linq/stream-xml-fragments-xmlreader
Content source URL
Document Version Independent Id
9274dd59-58d0-267a-b744-039c878f4fda
Article author
@dotnetcontent
Metadata
- ID: fdabaa66-5511-b61f-7e0b-f9202fbb26fb
- Service: dotnet-fundamentals