More Interchangeability

Team Fly 

Page 503

       Console.WriteLine(c1.FirstName)       Console.WriteLine(c1.LastName) End Sub Sub deser_UnknownElement(ByVal sender As Object, ByVal e As XmlElementEventArgs)            MsgBox(e.Element.Name & '' is not recognized. Deal with it. The problem is in line number " & _ e.LineNumber & " in the XML source file.") End Sub 

Notice that when you execute this program, the Output window displays the LastName, but not the FirstName (which was ignored in the input stream). Also, you can use the ObjectBeing-Deserialized property of the XmlElementEventArgs object to identify which object instantiated by your application is having the problem.

More Interchangeability

As you see in various examples in this chapter, XML is pervasive in .NET. You can quickly design an XML schema, then transform it into an ADO.NET DataSet structure with a click of the mouse (see the section titled "XML and DataSets" earlier in this chapter).

In various other contexts in .NET you also see XML popping up here and there—and often you need not do anything yourself because .NET creates the XML or schemas all by itself.

How easy is it to transform XML data (as opposed to a schema) into a database-style data table? As easy as clicking a Data tab in the VB.NET IDE. Try it.

Choose File image Open image File in VB.NET. Locate and load the sample XML file, c:\books.xml. You see a formatted view of the XML. Now click the Data tab at the bottom of the .NET IDE window. The XML is automatically translated into an editable data table, as shown in Figure 17.3:

image

FIGURE 17.3 .NET transforms XML into a DataSet with the click of a button.

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net