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

Resolving relative paths

Last post 04-06-2007 3:12 PM by AozineIC. 2 replies.
  • 04-06-2007 1:59 PM

    Resolving relative paths

    I'm quite new to both C# and XNA so sorry if this is an obvious question. I'm trying to load XML files that contain filenames of textures, so I'm using the XML importer to parse the data into one of my data structures and then use a custom ContentProcessor I've written to convert the each of the texture filenames into references to the actual Texture2D object. So far, I've got this:

        [ContentProcessor]
        class XImageGridProcessor : ContentProcessor<XImageGridXml, XImageGridData> {
            public override XImageGridData Process(
                      XImageGridXml input, ContentProcessorContext context) {
                XImageGridData grid = new XImageGridData();
                grid.Texture = new ExternalReference<Texture2DContent>(input.Texture);
                ... process the rest of the input structure ...
            }
        }

    The problem is that the filenames in the XML file are relative to where the XML file is on disk, so I keep getting an exception complaining that my ExternalReference does not contain an absolute path. Is there an easy way for me to get the path to my XML file in the ContentProcessor so that I can convert these relative paths to absolute ones?

  • 04-06-2007 2:31 PM In reply to

    Re: Resolving relative paths

    Answer

    The easiest way to do this is probably to put the ExternalReference directly into your XML, in which case the serializer will handle this for you and automatically de-relativize the paths based on the location of the XML file. 

    For a type defined like this:

        class MyClass
        {
            public ExternalReference<Texture> Texture;
        }

    The XML would look like:

        <XnaContent>
          <Asset Type="MyClass">
            <Texture>
              <Reference>#External1</Reference>
            </Texture>
          </Asset>
          <ExternalReferences>
            <ExternalReference ID="#External1" TargetType="Microsoft.Xna.Framework.Graphics.Texture">grass.tga</ExternalReference>
          </ExternalReferences>
        </XnaContent>
     

    XNA Framework Developer - blog - homepage
  • 04-06-2007 3:12 PM In reply to

    Re: Resolving relative paths

    That worked great - thanks very much!
Page 1 of 1 (3 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG