Partager via


Import sample data from an XML file

As an alternative to generating data on the fly, you can import an XML file to use as sample data. The advantage to this option is that you can quickly add the same sample data to multiple projects. The XML file can include paths to other files only if those file paths are relative to the location of the XML file. Make sure that those file paths are available to each project in which the XML file is used.

You do not have to add the XML file to your project to import the data. After the XML data is imported, the data is stored in a subfolder in the SampleData project folder. You can modify imported data by using the tools in the Data panel. Modifications that you make will not change the original XML file.

ConseilConseil

You can find examples of XML files on the Internet, or you can use a tool such as XML Notepad to generate an XML file. For more information, see How to use XML Notepad to create an XML document on the Microsoft Help and Support website.

To import an XML file as sample data

  1. To enable the sample data tools, open a XAML document on the artboard in Design view JJ169821.32be2832-9f81-4617-97e6-a4a3988a136c(fr-fr,VS.110).png or Split view JJ169821.5b79e600-984e-4f44-b8cd-6c1522832ad4(fr-fr,VS.110).png.

  2. If you do not see the Data panel, make sure that a check mark appears next to Data on the Window menu.

    For more information, see Add or remove a workspace panel.

  3. In the Data panel, click Create sample data JJ169821.30540d76-7256-43ce-b5d9-4b2edf3d339f(fr-fr,VS.110).png, and then click Import Sample Data from XML.

  4. In the Import Sample Data from XML dialog box, type a descriptive name for your data source in the Data source name field.

  5. In the XML file path or URL field, type the path of an existing XML file using one of the following formats:

    Optionally click the Browse button to browse to an XML file.

  6. Under Define in, select one of the following:

    • Project   Use this option to make the data available to all documents in the project.

    • This document   Use this option to make the data available only to the currently-open XAML document.

  7. If you want your application to be able to display sample data when you run it (F5), select Enable sample data when application is running. If you do not select this option, you will be able to see sample data on the artboard only during design time, and not at run-time.

  8. Click OK to close the New Sample Data dialog box and create the sample data.

    In the Projects panel, in a folder named SampleData, a subfolder is added for your new sample data source, containing the files required to define the data.

    In the Data panel, you can expand the nodes of your new data source to view the schema of your sample data.

  9. In the Data panel, examine the schema of your XML data to see whether you need to convert any of the simple properties to another type. For example, if one of the properties in the schema is the path of an image file, you can convert the property to an Image so that the image will be displayed when you drag the data to the artboard.

    JJ169821.cd4fc99c-b0df-42b6-83c3-331ebb1f8734(fr-fr,VS.110).png

Reimport the XML file of sample data

In the Data panel, you can modify the data that you import from an XML file. If you want to restore your data to the original values contained in the XML file, you can reimport the file.

To reimport the XML file of sample data

  1. In the Data panel, locate the data source that was imported from an XML file.

  2. Next to the name of the data source, click Data source options JJ169821.ae1fd260-4f84-420d-b196-45fde357d81d(fr-fr,VS.110).png, and then click Reimport Sample Data from XML.

  3. In the Browse for XML data source dialog box, browse to your XML file, or type the path or URL of the file in the File name field, and then click Open.

    The schema and values of the data source are updated to reflect the XML file, undoing all manual modifications. If the data was already displayed in an object on the artboard, the object is not updated to display the changed data until you drag the data onto the object again.

Voir aussi

Tâches

Generate sample data

Modify sample data

Autres ressources

Displaying data in controls