XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

XML doesn't compile through content pipeline (list within a list?)

Last post 03/11/2009 17:43 by IkiFoo. 2 replies.
  • 01/11/2009 18:53

    XML doesn't compile through content pipeline (list within a list?)

    I'm writing a level editor in which you can position entities (models) and the control points of Bezier curves. I'm trying to write the data to an XML file which can then be loaded through the Content Pipeline. However, I can't get it to work with the layout I have and I can't seem to make one that works.

    The layout of the class is as follows, with variable name followed by type

    LevelData (custom class)

    - beziers (BezierInfo class)
      - inner (List of Vector3)
      - outer (List of Vector3)

    - entities (List of EntityInfo class)
      - type (String)
      - ModelName (String)
      - position (Vector3)

    This is the XML file I've created to try and get a working file for the content pipeline

    <?xml version="1.0" encoding="UTF-8"?> 
    <XnaContent> 
      <Asset Type="DataTypes.LevelData"
        <!--Bezier Pairs Info--> 
        <beziers Type="System.Collections.Generic.List[DataTypes.BezierPairsInfo]"
          <Item> 
            <!--Inner Curve--> 
            <inner Type="System.Collections.Generic.List[Microsoft.Xna.Framework.Vector3]"
              <Item> 
                <X>8</X> 
                <Y>0</Y> 
                <Z>8</Z> 
              </Item> 
              <Item> 
                <X>5</X> 
                <Y>2</Y> 
                <Z>1</Z> 
              </Item> 
              <Item> 
                <X>-12</X> 
                <Y>0</Y> 
                <Z>4</Z> 
              </Item> 
            </inner> 
            <!--Outer Curve--> 
            <outer Type="System.Collections.Generic.List[Microsoft.Xna.Framework.Vector3]"
              <Item> 
                <X>13</X> 
                <Y>1</Y> 
                <Z>5</Z> 
              </Item> 
              <Item> 
                <X>7</X> 
                <Y>2</Y> 
                <Z>-4</Z> 
              </Item> 
              <Item> 
                <X>-13</X> 
                <Y>0</Y> 
                <Z>-2</Z> 
              </Item> 
            </outer> 
          </Item> 
        </beziers> 
        <!--Entity Info--> 
        <!--<Asset Type="DataTypes.EntityInfo[]">--> 
        <entities> 
          <Item> 
            <type>STATIC</type> 
            <modelName>Level\level_complete</modelName> 
            <Asset Type="Microsoft.Xna.Framework.Vector3"
              <X>0</X> 
              <Y>0</Y> 
              <Z>0</Z> 
            </Asset> 
          </Item> 
          <Item> 
            <type>STATIC</type> 
            <modelName>Models\tree_cave_only</modelName> 
            <Asset Type="Microsoft.Xna.Framework.Vector3"
              <X>20.1941</X> 
              <Y>0</Y> 
              <Z>20.23614</Z> 
            </Asset> 
          </Item> 
        </entities> 
      </Asset> 
    </XnaContent> 


    Ignore from <entities> downwards - I haven't gotten that far yet.

    This is the C# code to go along with it - the XML file is trying to save the data from an instance of LevelData

    using System; 
    using Microsoft.Xna.Framework; 
    using System.Collections.Generic; 
     
    namespace DataTypes 
        // information from entities 
        public struct EntityInfo 
        { 
            public String type; 
            public String modelName; 
            public Vector3 position; 
        } 
     
        // information from pairs of Bezier curves 
        public struct BezierPairsInfo 
        { 
            public List<Vector3> inner; 
            public List<Vector3> outer; 
        } 
     
        // level data shoved in a handy dandy place 
        public class LevelData 
        { 
            //public float versionNumber; 
            //public BezierPairsInfo[] beziers; 
            //public EntityInfo[] entities; 
            public List<BezierPairsInfo> beziers; 
            public List<EntityInfo> entities; 
        } 


    And this is the error I get when trying to compile the project with the XML file in Content

    Error 1 There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 9, position 12. C:\Users\Iki\Desktop\SVN\BG\trunk\Boogey-Editor\Editor\Content\levelFile.xml 9 12 Editor

    Any ideas? I'm guessing it's the list within a list, since the error is at the second Item tag.
  • 02/11/2009 15:57 In reply to

    Re: XML doesn't compile through content pipeline (list within a list?)

    That's not how IntermediateSerializer XML should look for this type. See here and here.
    XNA Framework Developer - blog - homepage
  • 03/11/2009 17:43 In reply to

    Re: XML doesn't compile through content pipeline (list within a list?)

    Thanks! I've been looking for a good XNA/XML reference and those links are great. :)

    Anyway, the problem was the way I was the formatting of Vector3 lists. Where I had this...

    <inner Type="System.Collections.Generic.List[Microsoft.Xna.Framework.Vector3]">  
              <Item>  
                <X>8</X>  
                <Y>0</Y>  
                <Z>8</Z>  
              </Item>  
              <Item>  
                <X>5</X>  
                <Y>2</Y>  
                <Z>1</Z>  
              </Item>  
              <Item>  
                <X>-12</X>  
                <Y>0</Y>  
                <Z>4</Z>  
              </Item>  
            </inner>  

    ...I should have had this...

    <inner>  
         8 0 8  
         5 2 1 
         -12 0 4 
    </inner>  

    Thanks very much for the help. :)
Page 1 of 1 (3 items) Previous Next