3 Replies - 997 Views - Last Post: 04 April 2012 - 09:37 AM

#1 Ntwiles  Icon User is offline

  • D.I.C Regular

Reputation: 61
  • View blog
  • Posts: 493
  • Joined: 26-May 10

Serializing Array into XML

Posted 19 March 2012 - 02:26 AM

I'm inexperienced with both XML and data serialization in general, and I'm getting quite a bit of trouble trying to successfully import an XML file through the content pipeline. I used the following tutorial which seemed to be pretty informative:

http://www.switchont...ontent-pipeline

But I'm finding myself unable to serialize a char array in any way that the compiler will accept. I'm trying to read into the following class:

    public class Level
    {
        public char[] map;
    }


And I'm using this bit of XML as a test:

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="SharedContent.Level">
    <map>
      <char>13</char>
    </map>
  </Asset>
</XnaContent>



Placing elements under a <char> tag is how the compiler serialized my char array, but when trying to load XML I've written this way, I'm given There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 5, position 8.

Apparently both elements and text are invalid, so I'm at a loss for what it actually is looking for. Can someone show me where I'm going wrong?

This post has been edited by Ntwiles: 19 March 2012 - 04:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Serializing Array into XML

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon




Reputation: 1325
  • View blog
  • Posts: 3,504
  • Joined: 03-May 10

Re: Serializing Array into XML

Posted 19 March 2012 - 06:39 AM

Are you serializing the data to create that XML file, or are you manually typing the information into that XML file and trying to deserialize it? If the former, let me see your method that serializes the data into XML and creates the file.
Was This Post Helpful? 0
  • +
  • -

#3 Ntwiles  Icon User is offline

  • D.I.C Regular

Reputation: 61
  • View blog
  • Posts: 493
  • Joined: 26-May 10

Re: Serializing Array into XML

Posted 19 March 2012 - 06:56 AM

It's the latter. I'm typing it in manually as a test for now. I plan to be serializing the the data into XML from a separate level editor application, but I haven't begun to implement that yet.

That format is based on a test I did where I wrote an array of random chars to an XML file; it stored the data the same way I'm trying to.

Incidentally I moved away to using a List instead of an array, and surprisingly Lists seem to be much easier to implement than arrays (especially the jagged array I was going to have to go with) for serializing to XML. So this is no longer a direct issue, but I'll still be grateful if someone could tell me what the problem was.
Was This Post Helpful? 0
  • +
  • -

#4 Mcguirk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-April 12

Re: Serializing Array into XML

Posted 04 April 2012 - 09:37 AM

Hi Ntwiles,
When dealing with arrays, the default XML serializer expects you to use <Item> tags for each element of the array, not the the array type (char in your case).

Try this XML:

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <Asset Type="SharedContent.Level">
    <map>
      <Item>13</Item>
    </map>
  </Asset>
</XnaContent>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1