Fix XmlDeserializer when XML uses same tag in nested elements #2339
+307
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
User description
Description
Replaces #2336
Auto-created Ticket
#2340
PR Type
Bug fix
Description
Fix XmlDeserializer to use Elements() instead of Descendants() for nested XML elements
Prevent deeply nested elements from being incorrectly included in parent lists
Handle duplicate element names by preferring shallowest RootElement match
Remove null values from namespace filtering and fix null-forgiving operators
Diagram Walkthrough
File Walkthrough
XmlDeserializer.cs
Refactor nested element handling with Elements() strategysrc/RestSharp.Serializers.Xml/XmlDeserializer.cs
Element() first, then DescendantsAndSelf() ordered by ancestor count
Elements() for direct children only, preventing nested list flattening
TryFindElementsByNameVariations() method supporting both direct
children and descendants modes
containing backticks
NestedElementTestClasses.cs
Add test classes for nested element scenariostest/RestSharp.Tests.Serializers.Xml/SampleClasses/NestedElementTestClasses.cs
structures
items
XmlDeserializerTests.cs
Add comprehensive tests for nested element fixestest/RestSharp.Tests.Serializers.Xml/XmlDeserializerTests.cs
items
not throw
children only