XmlImporter only allows one list item?

Hi all. I’m having a very strange issue with the XML importer. I have two very simple classes:

namespace CustomDataTypes {
  public class SpriteSheetData {
    public Dictionary<string, SpriteAnimation[]> Animations;
  }
}

namespace CustomDataTypes {
  public class SpriteAnimation {
    public string Name;
    public List<Rectangle> Frames;
  }
}

And this XML:

<?xml version="1.0" encoding="utf-8"?>
<XnaContent>
  <Asset Type="CustomDataTypes.SpriteSheetData">
    <Animations>
      <Item>
        <Key>monk_male</Key>
        <Value>
          <Item>
            <Name>walk_down</Name>
            <Frames>
              <Item>0 0 52 72</Item>
            </Frames>
          </Item>
        </Value>
      </Item>
    </Animations>
  </Asset>
</XnaContent>

This works great. It compiles fine, I loaded the data and all the objects inside it are of the appropriate type. However, as soon as I try to add another <Item> tag to the internal List of Rectangles, the XmlImporter produces an error of the form:

'Element' is an invalid XmlNodeType. Line 12, position 9.

Why the heck would the XmlImporter only be able to handle adding a single item to that List? If anyone has any insight into this, I would greatly appreciate it. Thanks!

I have worked with loading from xna, and making lists from the data… So I know it works!

The error you get points to where the 2nd item would appear in the xml file…
I cant remember the syntax rules for xml, but I would check the structure of your xml file, vs however you read from it… I used a foreach loop to iterate through items in my xml file.

It might be helpful to see your code for how you extract data from the xml and populate your list.

Hi monopalle. Thanks for the reply. I’m trying to use the content pipeline to load the compiled XML file, so I don’t have any code for parsing it explicitly. I just use Content.Load and it gives me a SpriteSheetData object with the correct structure as far as I can tell. This failure is actually happening when I try to compile the XML file into a XNB so the parsing doesn’t seem to be the problem. Would it be helpful if I posted a screenshot of the loaded object structure as seen in the debugger? I could grab that in a little bit.

Oh yeah, I forgot about the XNB conversion.
That might be the problem somehow.

Otherwise, getting back to what we were discussing before, what I mean is, you must have some code referring to the xml file?
Something that reads your xml file, finds a certain item, and adds a rectangle to your list for every instance found?

IF this is the case, it would be helpful to see as much code as possible, at least the part working with populating the rectangle list, and parsing xml data.

That’s the beauty of the XMLImporter and the IntermediateSerializer though…if you set things up right you don’t need to bother with custom parsing logic. All you have to do is call Content.Load on your XML asset and it takes care of all that serialization junk for you. See:

https://msdn.microsoft.com/en-us/library/ff604980.aspx

and

https://blogs.msdn.microsoft.com/shawnhar/2008/08/12/everything-you-ever-wanted-to-know-about-intermediateserializer/

Hmm… I think I see the point of your first classes there, now… The 2nd one is the code responsible for populating your list with rectangles.

Well, I havent done it like that before, but I have used something like:

foreach (item_x in my_xml_file)
{
my_list.Add( item_x.property_y);
}
Its only a few lines of code, I dont know that there are any draw backs?