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

Using the XML File
 
Let me begin by reiterating that using Web Matrix isn't the best way to create an XML file unless you like to do a lot of typing and don't want to see what your data actually looks like. That said, the ability to create XML files is important. When you use the XML File page template, you get a basic tag that starts you on your way. All you need to do is begin typing the elements and attributes for your XML file.
 
TIP Web Matrix provides a text editor for the XML files. This might seem problematic at first, but I've found it's quite useful. Most XML editors on the market, including XML Notepad, operate on the premise that the XML file you want to edit has "well-formed" XML. Some XML files won't meet this requirement in certain situations, such as some CONFIG files I've viewed. The fact that Web Matrix provides textediting functionality means you can view the errant XML file and fix it if required. The point is that Web Matrix provides you with another alternative-another tool for your toolkit.
 
This section looks at a relatively simple example. Learning to type XML by hand is actually a good idea because it helps you see problems in automatically generated XML later. Some of the elusive issues behind a relatively simple packaging technique begin to make sense as you spend more time working with XML. With this in mind, consider the XML code in Listing 7-2.
 
 Listing 7-2. A Simple XML File

 
 
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
 
<PhoneMessages>
   <
Date Day=
"09/16/02">
 
    <Message Name="George">
 
      "Hello, Sorry I missed you!"
 
    </Message>
     <
Message Name=
"Sam">
 
      "Are you gone again?"
 
    </Message>
   </
Date
>
   <
Date Day=
"09/17/02">
 
    <Message Name="Ann">
 
      "Want to go fishing Thursday?"
 
    </Message>
   </
Date
>
   <
Date Day=
"09/18/02">
 
    <Message Name="Jerry">
 
      "Hope to see you tomorrow!"
 
    </Message>
     <
Message Name=
"Samantha">
 
      "Call the office ASAP!"
 
    </Message>
     <
Message Name=
"Jan">
 
      "Give me a call at work!"
 
    </Message>
   </
Date
>
 </
PhoneMessages
>
 
This XML is well formed because it includes a header, and each of the elements has an opening and closing tag. Each element contains either another element or at least one attribute. The attributes take two different forms. You give the attribute a name and place it within the tag, or your can place it between an opening and closing tag. The specification doesn't require indenting. However, most developers find it useful for reading the XML in this format. Figure 7-7 shows how this XML file looks in XML Notepad.
 
 
 
Figure 7-7.Writing XML by hand can reward you with a better understanding of how this data storage format works.

Total Pages : 8 45678

comments