After hours and hours of using the google machine to figure out how to load an XML file into my Silverlight app, a former colleague pointed me to the most likely of places – the Silverlight Quick start guide.

C# Solution:

// Load the RSS file into XElement and display the content of the XML tree on the page. // XmlXapResolver is used to load the file from the application's XAP package.

XElement rss = XElement.Load("rss.xml");
OutputTextBoxLoadRss.Text = rss.ToString();

This will load an XML file from the ClientBin and then write it out to a textblock.  Surprisingly simple for the effort involved in trying to find this.

My next step was to get this to work in an locally launch browser or a standalone Out Of Browser application.  The trick here is to embed the XML file in the XAP package.  XAP files are just a ZIP file with a different extension. Make sure you have “Hide known file extensions” turned OFF.  You need to be able to see all file extensions or this is going cause some problems. Rename the file and only change the file extension from .xap to .zip    Now drop your XML file into the zip and rename back to .xap

Note that you will have to do this every time you rebuild as the XAP package is replaced.

Im sure there is a way to include the XML file as a resource to ensure it gets packaged but I did not test this theory out yet.

You should now be able launch the local html file and the app should be able to load the local XML. You can even right click and install Out Of Browser and this will continue to work as long as you don’t move the folder from where you installed it so choose wisely.