The similar parts should be extracted to a common method to make it easier to maintain.
while / if XmlNodeType.Element / else XmlNodeType.EndElement is the same for both collection and non-collection branches.