Monogame Xml Importer - How does it work?

I’ve been trying to get the xml importer to convert my xml file to xnb.

When I have a simple xml file which inside XnaContent is

Asset
UnitName Character /UnitName
Speed 30 /Speed
/Asset

Which gives me System.Xml.XmlException: ‘Element’ is an invalid XmlNodeType.

I don’t really understand. Is the importer only for serialization? If that is the case than why don’t you name is something more understandable?

What is the use for the Xml Importer that is provided through Monogame?

Are you trying to serialize a custom class you’ve made, eg something that’s not under MonoGame framework? If so, you need to build the assembly that contains that class as a dll and add reference from the Content Manager to it (and unfortunately, you can’t reference your own exe, because the reference is used during compilation. you need to make an external dll).

Anyway, the following is an example of a working XML from one of my projects, just so you’ll see a valid syntax:

<?xml version="1.0" encoding="utf-8"?>
<XnaContent xmlns:ns="Microsoft.Xna.Framework">

  <Asset Type="GeonBit.UI.DataTypes.TextureData">
    <FrameWidth>0.28</FrameWidth>
    <FrameHeight>0.0</FrameHeight>
  </Asset>

</XnaContent>

The class GeonBit.UI.DataTypes.TextureData is defined in a dll I have a reference to.

Hope this somehow helps!

(I ignored the second part of your question because I don’t know the answer of it, eg if the XML importer can be used to something other than serializing objects).

Thank you for you answer. You kind of answered my question by not knowing :stuck_out_tongue: I’ve concluded that the importer is probably only meant for serialization of external assemblies.