Workshop

for RuBoard

This workshop will help reinforce the concepts covered in today's lesson.

Quiz

1:

What is the difference between the GetXml and WriteXml methods of the DataSet class?

A1:

GetXml simply returns a string containing the XML representation of the data in a DataSet , whereas WriteXml is overloaded to support writing to streams, files, the XmlReader , and TextReader objects. For performance reasons, the WriteXml method is usually preferred.

2:

When mapping a schema to a DataSet , what element in the XSD maps to tables in the DataSet ?

A2:

The complexType element of the XSD maps to DataTable objects in the DataSet .

3:

What is the process of inference and how is it used by the DataSet ?

A3:

Inference refers to the process of inferring the XSD from an existing XML document. Inference is used when the InferXmlSchema and ReadXml methods are called and passed XML documents that are schemas or that contain in-line schemas. The process uses specific rules to determine which elements map to tables and which to columns , but the process is non-deterministic in that two documents created from the schema may produce different DataSet structures. The inference process is also not necessarily lossless, particularly when elements contain both text and child elements.

4:

What is the purpose of the XmlDataDocument ?

A4:

The XmlDataDocument class is used to provide a DOM view of a DataSet that is synchronized with the DataSet using events behind the scenes. The XmlDataDocument class enables developers to work with the data as if it were an XML document and can then utilize the features of XML documents such as XPath queries and XSL transformation.

Exercise

Q1:

Write a method that reads the provided sales.xml file into a DataSet . Then change its XML representation by changing the id attribute of the Store element to an element and then writing the new schema and data to a file.

A1:

One possible solution is shown in the following listing. Note that because of the inference rules, the Store element is actually represented in the third of the three DataTable objects created.

 Dim dsSales As New DataSet() ' Read in the file dsSales.ReadXml("sales.xml", XmlReadMode.InferSchema) ' Change the mapping to element dsSales.Tables(2).Columns("id").ColumnMapping = MappingType.Element ' Write out the schema and data dsSales.WriteXml("sales2.xml", XmlWriteMode.WriteSchema) 
for RuBoard


Sams Teach Yourself Ado. Net in 21 Days
Sams Teach Yourself ADO.NET in 21 Days
ISBN: 0672323869
EAN: 2147483647
Year: 2002
Pages: 158
Authors: Dan Fox

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