13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

{}DataTable dt = CreateTempTable(dv);WriteDataTable(dt, outputFile, mode);You create a temporary DataTable object and then serialize it to <strong>XML</strong> us<strong>in</strong>g thepreviously def<strong>in</strong>ed methods. The structure of the <strong>in</strong>ternal CreateTempTable rout<strong>in</strong>e isfairly simple, as shown here:private static DataTable CreateTempTable(DataView dv){// Create a temporary DataTable with the same structure// as the orig<strong>in</strong>alDataTable dt = dv.Table.Clone();// Fill the DataTable with all the rows <strong>in</strong> the view<strong>for</strong>each(DataRowView rowview <strong>in</strong> dv)dt.ImportRow(rowview.Row);}return dt;The ImportRow method creates a new row object <strong>in</strong> the context of the table. Like manyother ADO.<strong>NET</strong> objects, the DataRow object can't be referenced by two conta<strong>in</strong>erobjects at the same time. Us<strong>in</strong>g ImportRow is logically equivalent to clon<strong>in</strong>g the row andthen add<strong>in</strong>g the clone as a reference to the table. Figure 9-8 shows a DataView objectsaved to <strong>XML</strong>.Figure 9-8: Sav<strong>in</strong>g a DataView object to <strong>XML</strong>.B<strong>in</strong>ary Data Serialization342

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!