Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect logic in XmlReader's example (#43799) #44054

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

scale-tone
Copy link

@scale-tone scale-tone commented Dec 21, 2024

(#43799 is now 3 weeks old without even being triaged, so fixing it myself)

The code sample for XmlReader is incorrect. It relies on the fact that the input XML has some formatting in it. Without formatting the code returns wrong results.

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.

Here is the code to address the issue.


Internal previews

📄 File 🔗 Preview link
docs/standard/linq/stream-xml-fragments-xmlreader.md How to stream XML fragments from an XmlReader (LINQ to XML)

@scale-tone scale-tone requested a review from a team as a code owner December 21, 2024 19:11
@dotnetrepoman dotnetrepoman bot added this to the December 2024 milestone Dec 21, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates PR is created by someone from the .NET community. label Dec 21, 2024
@scale-tone
Copy link
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant