locked
Unable to read xml file at content/sample.xml RRS feed

  • Question

  •  I am trying to display xml contents in a DOm element. Below code does not works. Could someome tell what I am doing wrong. The code never goes inside first callback. 

    Js file is in JS folder which is at same hierarchy as Content folder.

    Windows.Storage.StorageFile.getFileFromPathAsync(".\..\Content\sample.xml").then(
                      function (f) {
                           file = f;
                          var promise = Windows.Data.Xml.Dom.XmlDocument.loadFromFileAsync(file, new Windows.Data.Xml.Dom.XmlLoadSettings()).then(function (xml) {
                             document.getElementById("textarea").innerText = xml.getXml();
                          });
                      });


    • Edited by Map user Tuesday, October 2, 2012 6:08 AM sample
    Tuesday, October 2, 2012 6:07 AM

Answers

All replies

  • relative paths (with "..") are not supported. use ms-appx: or mx-appdata: as described here:

    http://msdn.microsoft.com/en-us/library/windows/apps/Hh781215.aspx

    • Marked as answer by Song Tian Thursday, October 18, 2012 7:03 AM
    Thursday, October 4, 2012 5:32 AM
  • hi

    I guess this is what you need

        function readItemsXml() {
            Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(dataFolder).then(function (folder) {
                folder.getFileAsync(filename)
               .then(function (sampleFile) {
                   var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings;
                   loadSettings.prohibitDtd = false;
                   loadSettings.resolveExternals = false;
                   return Windows.Data.Xml.Dom.XmlDocument.loadFromFileAsync(sampleFile, loadSettings);
                   //return  Windows.Storage.FileIO.readTextAsync(sampleFile);
               }).done(function (xmlData) {
                   debugger;
                   // Data is contained
               }, function () {
                   // Data not found
               });
            });
        }
    
        readItemsXml();
    

    Sunday, April 21, 2013 6:02 AM