FREE BOOK

Chapter 7: Web Matrix and XML

Posted by Apress Free Book | XML .NET January 13, 2009
In this chapter Use the XML Support ,XML Notepad ,XMLEditGrid Control,XML File Page,XSL Transform Page,XML Schema Page and XML Data Display Application

Working with Microsoft XML Notepad

XML is almost, but not quite, readable by the average human. Reading simple files is almost trivial, but once the data gets nested a few layers deep, reading it can become tiresome. That's why you should have a tool for reading XML in your developer toolkit. The only problem is that some of these tools cost quite a bit for the occasional user. Microsoft has remedied this problem a little with the introduction of XML Notepad
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxml/html/xmlpaddownload.asp) This utility is free for the price of a download and does a reasonable job of reading most XML files. The current version, 1.5, is in beta as of this writing. In addition, although the Web site doesn't mention it, this version works fine with both Windows 2000 and Windows XP. The following sections provide a brief overview of this tool. We'll use this tool in several sections of the book to read XML data, so you'll want to download a copy.

Opening XML Files

When you start XML Notepad, you'll see a blank project. Use the File >Open command to display an Open dialog box that allows you to open XML files from a local drive or from aWeb site. All you need is a filename (and path) or a URL to get started.

TIP Not all XML files have an XML file extension.We've already seen one case in the book where a CONFIG file was actually an XML file in disguise. Often, you'll find that the file extension matches the customized use of the file, rather than the actual content.When in doubt, try to open a file that looks like it contains XML data to see if XML Notepad will make it easier to understand.

Figure 7-1 shows the content of amovie database example I created by exporting the MovieGuide database ExistingMovies table to the Movie.XML (You'll find several XML files to view in the \Chapter 07\Sample XML Data folder of the source code, available from the Downloads section on the Apress site at
http://www.apress.com/book/download.html.) Notice that the name of the elements matches the name of the table for the movie database (found in the Movie.XML file). Likewise, each of the child elements matches the name of one of the fields within the table. The right pane shows the data contained within each one of the child elements.



Figure 7-1. The names of the elements are important when working with exported data in XML format.

TIP If you want to use XML from your SQL Server 2000 installation, then you'll want to download the XML feature packs found at

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/001/824/msdncompositedoc.xml.

These feature packs add to the capabilities already found in SQL Server 2000. In addition, they help you keep your setup current by ensuring that your SQL Server 2000 installation always meets the specification requirements.

Modifying Existing Data and Creating New Data

You can use XML Notepad for more than just viewing data. Creating new data for testing purposes is relatively painless once you see the exported data from an existing database. In fact, we'll create some sample data in this section for use in an application later. The following steps will get you started.

  1. Create a blank project using the File >New command.
     
  2. Type the name of the data set in the Root object. The example uses SampleData as a name, but you'll want to select something a little more descriptive for a production application.
     
  3. Rename the first element to reflect the new table. The example application uses NewDataElement as the name. DBMSs normally use the database name for the Root object and the table name for the first element. (See Figure 7-1 for an example of actual database output.)
     
  4. Add a new child element using the options on the Insert menu. You'll notice that the first element changes into a folder. Type the name of the first data column in this element. The example uses Data1 for the first child element. However, a database would use the name of the first field in the selected table (see Figure 7-1).
     
  5. Add additional columns as needed until you complete one record's worth of entries. The example uses Data2 and Data3 as entries to complete one record in the sample database, but you should also look at Figure 7-1 as another example of what you could do.
     
  6. Type values for each of the child elements. Now that you have one complete record, you can use the Duplicate command to create copies of it. Each copy will become one record within the XML database.
     
  7. Right-click the NewDataElement folder and choose Duplicate from the context menu. The example provides three records for the sample, but you can include any number you wish. Figure 7-2 shows the structure and contents of the SampleData.XML file. It also shows the content we'll use for the example.


Figure 7-2. Creating an XML database using XML Notepad is relatively easy as long as you follow a few rules.

Now that you've seen what XML Notepad can do, you need to realize that other vendors do provide other alternatives. XML Notepad doesn't have some of the bells and whistles of high-end products such as XML Spy (
http://www.xmlspy.com/) However, XML Notepad is a good alternative if you only use an XML editor occasionally and don't want to spend any money. The important consideration is that you have an XML editor that you can use to view the output from your applications.

Total Pages : 8 12345

comments