locked
Windows 8 app - JS - XML

    Question

  • Am working in Windows 8 HTML/JS app. I want to open an XML file and bind it.
    Wednesday, February 13, 2013 11:02 AM

Answers

  • To return the file, you probably want some code like this:

        Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(foldername).then(function (folder) {
            return folder.getFileAsync(filename);
            }).done(function (file) {
                var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings;
                loadSettings.prohibitDtd = false;
                loadSettings.resolveExternals = false;
                return Windows.Data.Xml.Dom.XmlDocument.loadFromFileAsync(file, loadSettings);
            }).then(function (doc) {
                dataText = doc.getXml();
                xmlDoc = doc;

    To bind it, you should be able to use the sample grid template app that MS provide when you create a project.

    Obviously, depending on the structure of your XML you may need to do some tweaking.

    Wednesday, February 13, 2013 12:38 PM

All replies

  • To return the file, you probably want some code like this:

        Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(foldername).then(function (folder) {
            return folder.getFileAsync(filename);
            }).done(function (file) {
                var loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings;
                loadSettings.prohibitDtd = false;
                loadSettings.resolveExternals = false;
                return Windows.Data.Xml.Dom.XmlDocument.loadFromFileAsync(file, loadSettings);
            }).then(function (doc) {
                dataText = doc.getXml();
                xmlDoc = doc;

    To bind it, you should be able to use the sample grid template app that MS provide when you create a project.

    Obviously, depending on the structure of your XML you may need to do some tweaking.

    Wednesday, February 13, 2013 12:38 PM
  • try like this

    var fileUri = new Windows.Foundation.Uri('ms-appx:///myFolder/myConfig.xml');
    var file = Windows.Storage.StorageFile.getFileFromApplicationUriAsync(fileUri);

    now use the file to parse and handle the data as needed.

    or

    http://code.msdn.microsoft.com/windowsapps/XML-API-Scenario-Sample-42ce708b

    check this

    Wednesday, February 13, 2013 12:45 PM