troubleshooting Question

Deserialize XML to array of arrays

Avatar of wlevy
wlevy asked on
2 Comments1 Solution742 ViewsLast Modified:
Given the following sample XML snippet:

  <Item ID="42" Text="Menu Item #1">
        <Role Name="Role #1" />
        <Role Name="Role #2" />
        <Role Name="Role #2" />
        <Role Name="Role #3" />
  <Item> ... </Item>

I have been trying to create a class to deserialize the XML to a List<MenuItem> such that each MenuItem has a nullable Requirements member, and the Requirements member if not null can have an array of RoleGroups, and each RoleGroup can have an array of Roles.

So we would wind up with a variable of type List<MenuItem> with the first element looking like this:
Text="Menu Item #1"
-- RoleGroup[0]
---- Role[0] = "Role #1"
---- Role[1] = "Role #2"
-- RoleGroup[1]
---- Role[0] = "Role #3"
---- Role[1] = "Role #4"

I am using a System.Xml.Serialization.XmlSerializer(typeof(Menu)) to deserialize the XML.

I've run into a number of stumbling blocks and really need some help on this. Tried using XSD.exe to create an XSD and then create a class, but it doesn't work correctly. I would be happy with a solution that involves tweaking the generated XSD or the generated class, or coding the class by hand, whatever it takes.

I was able to get an array of Roles directly under the Requirements node, but I need to add the RoleGroup layer.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros