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

Loading XML for a 2D Wireframe

Last post 06/11/2009 16:29 by Shawn Hargreaves. 2 replies.
  • 06/11/2009 13:36

    Loading XML for a 2D Wireframe

    Hi all,

    I'm having a little bit of difficulty finding any resources on the permitted layout of XML files which can be loaded by the XNA content pipeline. Essentially, I've written a python script that exports vertices and edges (lines) from blender to an XML format of my own design, this format looks like this (taken straight from my resulting XML file):

    <?xml version="1.0" encoding="utf-8" ?> 
    <object> 
      <vertices> 
          <vertex x="0.000000" y="0.000000" z="0.000000"/> 
          <vertex x="1.000000" y="-1.000000" z="-0.003800"/> 
          <vertex x="2.000000" y="-1.000000" z="-0.003800"/> 
          <vertex x="2.200000" y="-0.600000" z="-0.003800"/> 
          <vertex x="2.400000" y="-0.600000" z="-0.003800"/> 
          <vertex x="2.700000" y="-1.400000" z="-0.003800"/> 
          <vertex x="3.100000" y="-1.600000" z="-0.003800"/> 
          <vertex x="3.500000" y="-1.400000" z="-0.003800"/> 
          <vertex x="3.700000" y="-0.800000" z="-0.003800"/> 
          <vertex x="4.000000" y="-0.800000" z="-0.003800"/> 
      </vertices> 
      <edges> 
          <edge vert0="0" vert1="1"/> 
          <edge vert0="2" vert1="1"/> 
          <edge vert0="3" vert1="2"/> 
          <edge vert0="4" vert1="3"/> 
          <edge vert0="4" vert1="5"/> 
          <edge vert0="6" vert1="5"/> 
          <edge vert0="7" vert1="6"/> 
          <edge vert0="8" vert1="7"/> 
          <edge vert0="8" vert1="9"/> 
      </edges> 
    </object> 
     

    Unfortunately, XNA doesn't like this format, refusing to compile when its included in the project. I have since descovered that there is a propriatary format for XML in XNA. I've found a couple of examples of loading XML (e.g. Nick Gravelyn's article on Ziggyware: http://www.ziggyware.com/readarticle.php?article_id=150), but this doesn't appear to have the level of detail I'm looking for (i.e. dealing with nested elements).

    I'm fairly new to XNA development and I was wondering if anyone could point out some tutorials that focus on XML files for XNA specifically or some sort of reference as to valid XML markup for XNA and how to load and process them. Ultimately, I'm looking for a List of Vector2 or Vector3 containing the information defined in the vertices section and a List of int[2] (indices to vertices) defining the lines.

    Does anyone have any ideas?

    Much appreciated,
    Andy

  • 06/11/2009 14:14 In reply to

    Re: Loading XML for a 2D Wireframe

    If you want to do custom XML and parse it yourself, you have to change the file's Build Action to "Copy if Newer" instead of "Compile"... Then you can open the file and parse it at runtime.

    Here's the first random sample I found googling around: http://watchhogstories.wordpress.com/2007/05/15/xna-tutorial-1-reading-sequential-data-from-an-xml-file/
  • 06/11/2009 16:29 In reply to

    Re: Loading XML for a 2D Wireframe

Page 1 of 1 (3 items) Previous Next