Skip to content

Fix XmlDeserializer to correctly handle nested elements and ambiguous root element selection  #2337

@qodo-free-for-open-source-projects

Description

Description

  • XML deserialization was incorrectly flattening nested lists by using Descendants() instead of Elements(), causing deeply nested items to be included in parent lists
  • Root element selection failed when multiple elements shared the same name at different nesting levels, throwing InvalidOperationException
  • RemoveNamespace method was creating null attribute entries, causing potential deserialization errors
  • Generic type names containing backticks were being used as invalid XML element names

Deliverables

  • Root Selection: Implement shallowest-first matching strategy that prefers direct children via Element() before searching descendants, with ordering by ancestor count
  • List Deserialization: Refactor HandleListDerivative to identify container elements first, then use Elements() for direct children only instead of Descendants()
  • Null Filtering: Add Where() clause in RemoveNamespace to filter out null attribute values
  • Name Validation: Introduce IsValidXmlElementName() check to skip invalid XML names containing backticks from generic types
  • Test Coverage: Add comprehensive unit tests covering nested lists, duplicate element names, container-based lists, and multi-level nesting scenarios

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions