Skip to content

Code sample is incorrect in XmlReader's howto #43799

Closed
@scale-tone

Description

@scale-tone

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

https://github.com/dotnet/docs/blob/live/docs/standard/linq/stream-xml-fragments-xmlreader.md

Document Version Independent Id

9274dd59-58d0-267a-b744-039c878f4fda

Article author

@dotnetcontent

Metadata

  • ID: fdabaa66-5511-b61f-7e0b-f9202fbb26fb
  • Service: dotnet-fundamentals

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotnet-fundamentals/svcokr-qualityContent-quality KR: Concerns article defects (bugs), freshness, or build warnings.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions