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.
Suggerimento |
---|
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
To enable the sample data tools, open a XAML document on the artboard in Design view or Split view .
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.
In the Data panel, click Create sample data , and then click Import Sample Data from XML.
In the Import Sample Data from XML dialog box, type a descriptive name for your data source in the Data source name field.
In the XML file path or URL field, type the path of an existing XML file using one of the following formats:
A fully-qualified path, such as C:\sampledata\data.xml.
A relative path, such as data.xml (if the XML file has been added to the project folder).
An HTTP address, such as http://rss.msnbc.msn.com/id/3032127/device/rss/rss.xml.
Optionally click the Browse button to browse to an XML file.
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.
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.
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.
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.
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
In the Data panel, locate the data source that was imported from an XML file.
Next to the name of the data source, click Data source options , and then click Reimport Sample Data from XML.
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.