Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (4 posts)

Loading Raw XML Files in WP7

Last post 3/25/2010 11:14 PM by Nick Gravelyn. 3 replies.
  • 3/25/2010 6:39 PM

    Loading Raw XML Files in WP7

    I've got some data in .xml files that I want to use as-is in my game.  In older versions of XNA, I was able to add the .xml file to the Content, set the "Build Action" to "None", and set "Copy to Output Directory" to "Copy If Newer" and I could load it with a simple XDocument.Load() command.


    So for example, if I had \Levels\Level0\def.xml, I could load it with:
    XDocument level = XDocument.Load(@"Content\Levels\Level0\def.xml");


    I'm now trying to port my game to the new Windows Phone 7 platform, but the process seems to be different, 'cause I'm getting an error every time I try to load.  It's not seeing my raw .xml file in the application .xap package.  Is what I want to do still possible on the WP7 platform?
  • 3/25/2010 7:02 PM In reply to

    Re: Loading Raw XML Files in WP7

    Answer
    Reply Quote
    The filesystem on WP7 is a bit different and I don't think that overload of XDocument.Load works because of it. You'll need to instead pass in a stream which you can get with the TitleContainer.OpenStream API like this:

    XDocument level = XDocument.Load(TitleContainer.OpenStream(@"Content\Levels\Level0\def.xml")); 

    Hope that helps!
  • 3/25/2010 10:48 PM In reply to

    Re: Loading Raw XML Files in WP7

    This worked (Thank you!) but I think it exposed another issue that I was having.

    When I tested this out in a dummy program that I threw together, it worked fine.  However my original program had spaces in the Project name (bad programmer, bad!) and it still wasn't seeing the file with this new method.  It actually looks like none of the content files from the Content project were getting added to the final project.  Is that a known issue?
  • 3/25/2010 11:14 PM In reply to

    Re: Loading Raw XML Files in WP7

    Actually the files are there (hint: rename a XAP to ZIP and you can extract it to verify that files made it). It's a bug in the CTP where filepaths with spaces don't work and report that the file can't be found. The workaround is don't use spaces, but this won't be an issue in the final release.
Page 1 of 1 (4 posts) Previous Discussion Next Discussion