About the Book
Get the expert advice you need to succeed
in building .NET-connected applications with XML!
XML is everywhere in the Microsoft®
.NET Framework, from Remoting to Web services and from data access to configuration.
Learn about the extensive XML core classes in .NET and find out how to
program against its parser in this in-depth guide—written by a popular
programming author and consultant on cutting-edge technologies such as
Microsoft ASP.NET and Microsoft ADO.NET. You’ll find authoritative explanations
of technologies such as schemas, transformations, and XPath, plus extensive
discussion of data access issues such as synchronization and serialization,
the DiffGram format, and the XML extensions in Microsoft SQL Server™ 2000.
Along the way, you’ll learn exactly how to get the best performance out
of XML in the .NET world. You’ll also get answers to common questions such
as, “When should I use XML Web services instead of Remoting?” Topics covered
include:
XML CORE CLASSES IN THE .NET FRAMEWORK
• The .NET XML parsing model
• XML readers and writers
• Validating readers and writers
• XML Schema
XML DATA MANIPULATION
• The XML DOM in .NET
• XPath
• XSLT
XML AND DATA ACCESS
• XML extensions in SQL Server 2000
• DataSet serialization
• The DiffGram format
APPLICATION INTEROPERABILITY
• The XML Serializer
• .NET Remoting
• XML Web services
• XML data islands
• Configuration files
Related Books
The Microsoft® Platform Ahead
Network Programming for the Microsoft® .NET Framework
Microsoft® .NET and J2EE Interoperability Toolkit
Table of Contents
Acknowledgments
xvii
Introduction
xix
PART I XML CORE CLASSES IN THE
.NET FRAMEWORK
1 The .NET XML Parsing Model
3
XML in
the .NET Framework 4
Related XML Standards 4
Core Classes for Parsing 7
XML and ADO.NET 8
Application Configuration 9
Interoperability 10
From MSXML to .NET Framework Classes 11
COM and .NET Framework XML Core Services 11
Using MSXML in the .NET Framework 12
The .NET
Framework XML API 13
.NET Framework Readers and Writers 15
The Cursor-Like Approach 16
XML Readers 16
XML Writers 18
The XML Document Object API in .NET 19
XPath Expressions and XSLT 20
Further
Reading 22
2 XML Readers
25
The Programming
Interface of Readers 25
The XmlReader Class 27
Specialized Reader Classes 33
Parsing
with the XmlTextReader Class 34
Accessing Nodes 35
Accessing Attributes 40
Handling XML Exceptions 44
Handling White Spaces 44
Resolving Entities 45
Resolving External References 46
Reading Large Streams 47
The NameTable Object 49
Designing a SAX Parser with .NET Tools 50
Parsing
XML Fragments 52
Parsing Well-Formed XML Strings 53
Fragments and Parser Context 54
Writing
a Custom XML Reader 56
Mapping Data Structures to XML Nodes 57
Mapping CSV Files to XML 58
Implementing a CSV-to-XML Reader 59
The CSV XML Reader in Action 69
Readers
and XML Readers 72
Further
Reading 74
3 XML Data Validation
75
The XmlValidatingReader
Class 76
Supported Validation Types 76
The XmlValidatingReader Programming Interface 78
The XmlValidatingReader in Action 81
Under
the Hood of the Validation Process 89
Incremental Parsing 90
A Cache for Schemas 92
Validating XML Fragments 95
Using
DTDs 97
Developing a DTD Grammar 97
Validating Against a DTD 99
Usage and Trade-Offs for DTDs 100
Using
XDR Schemas 101
Overview of XDR Schemas 102
Validating Against an XDR 104
Using
the XML Schema API 106
What Is a Schema, Anyway? 107
Defining an XSD Schema 112
The .NET Schema Object Model 120
Validating Against an XSD Document 130
Further
Reading 133
4 XML Writers
135
The XML
Writer Programming Interface 136
The XmlWriter Base Class 138
The XmlTextWriter Class 144
Writing
Well-Formed XML Text 147
Building an XML Document 148
Formatting Text 156
Supporting Namespaces 157
Writing Encoded Data 162
XML Validating Writers 168
Writing
a Custom XML Writer 170
Implementing an ADO Recordset XML Writer 170
The XmlRecordsetWriter Programming Interface 171
Testing the XmlRecordsetWriter Class 176
Comparing Writers and XML Writers 178
A Read/Write
XML Streaming Parser 179
Designing a Writer on Top of a Reader 180
Built-In Support for Read/Write Operations 180
Designing the XmlTextReadWriter Class 181
Testing the XmlTextReadWriter Class 185
A Full-Access CSV Editor 192
Further
Reading 199
PART II XML DATA MANIPULATION
5 The XML .NET Document Object
Model 203
The XML
DOM Programming Interface 204
The XmlDocument Class 206
The XmlNode Base Class 213
Working
with XML Documents 219
Loading XML Documents 219
Extracting XML DOM Subtrees 224
Updating Text and Markup 225
Selecting Nodes by Query 226
Creating
XML Documents 228
Appending Nodes 229
Appending Attributes 232
Persisting Changes 233
Extending
the XML DOM 234
Custom Node Classes 234
Building a Hot-Plugging XML DOM 235
Further
Reading 244
6 XML Query Language and Navigation
245
What
Is XPath, Anyway? 246
Context of XPath Queries 246
Location Paths 250
Links Between Documents 252
XPath
in the XML DOM 253
The XML DOM Node Retrieval API 254
The Sample XPath Evaluator 256
The .NET
XPath Navigation API 263
The XPathNavigator Class 265
XPath Navigators and XML Readers 266
The XPathNavigator Programming Interface 267
XPath Expressions in the .NET Framework 273
Sorting the Node-Set 277
XPath Data Stores 280
XPath
Iterators 284
The XPathNodeIterator Class 285
Visiting the Selected Nodes 286
Further
Reading 288
7 XML Data Transformation
291
What
Is XSLT, Anyway? 292
XSLT Template Programming 293
XSLT Instructions 295
From XML to HTML 299
From Schema to Schema 303
The .NET
Framework XSLT Processor 305
A Quick XSLT Transformer 306
The XslTransform Class 308
Under the Hood of the XSLT Processor 312
Applying
Transformations 315
Design Considerations 317
Asynchronous Transformations 318
Output Formats 322
Passing and Retrieving Arguments 323
Practical
Examples 326
Transforming DataSet Objects into Recordset Objects 326
The XML Web Server Control 332
XSLT
Extension Objects 336
Processing Embedded Scripts 336
Passing Managed Objects to the Style Sheet 340
Further
Reading 343
PART III XML AND DATA
ACCESS
8 XML and Databases
347
Reading
XML Data from Databases 348
XML Extensions to the SELECT Statement 350
Limitations of FOR XML 353
Client-Side XML Formatting 354
Creating XML Views 355
XML Data
Readers 360
Reading from XML Queries 362
Under the Hood of ExecuteXmlReader 366
Reading from Text Fields 367
An XML Reader for Data Readers 368
Using XML with OLE DB Data Providers 371
A Disconnected
XML Data Reader 372
The XmlDataDocument Class 372
Synchronizing with a DataSet Object 373
XML Data Fidelity 374
Writing
XML Data to Databases 375
The OPENXML Rowset Provider 376
XML Bulk Loading 378
The Updategram Template 382
SQLXML
Managed Classes 386
The SqlXmlCommand Class 387
The SqlXmlParameter Class 393
The SqlXmlAdapter Class 394
Further
Reading 397
9 ADO.NET XML Data Serialization
399
Serializing
DataSet Objects 400
The DataSet Object's Embedded API for XML 402
Writing Data as XML 403
Writing Schema Information 406
Customizing the XML Representation 411
Rendering Data Relations 413
Serializing
Filtered Views 417
Serializing DataTable Objects 417
Inside the DataView Object 419
Binary
Data Serialization 422
Ordinary .NET Framework Serialization 422
Custom Binary Serialization 424
Loading
DataSet Objects from XML 428
Building DataSet Objects 428
Reading Schema Information 431
Inferring Schema Information 432
Loading from Custom Readers 436
Further
Reading 442
10 Stateful Data Serialization
443
Overview
of the DiffGram Format 444
The Current Data Instance 446
DiffGram Format Annotations 448
The Original Data Section 452
Tracking Pending Errors 455
The DiffGram
Viewer Application 457
Persisting a DataSet Object to a DiffGram 459
Loading a DataSet Object from a DiffGram 460
Schema Information in the DiffGram 461
A Save-and-Resume
Application 464
Setting Up the Application 464
Creating the Local Data Store 466
Reviewing and Rejecting Changes 467
Submitting Changes 469
Further
Reading 473
PART IV APPLICATIONS INTEROPERABILITY
11 XML Serialization
477
The Object
Serialization Process 477
The SOAP Formatter 478
From SOAP to XML Serialization 481
The XML
Serializer 483
The Programming Interface 483
Serializing Objects to XML 487
Deserializing XML Data to Objects 496
Shaping
the XML Output 499
XML Serialization Attributes 499
Overriding Attributes 503
Mapping
SQL Server Data to Classes 506
Overriding the Class Name 507
Overriding Class Properties 508
Mixing Overrides and Events 509
Populating Collection Properties 510
Inside
the XML Serializer 513
The Temporary Assembly 513
Serialization Writers and Readers 517
Further
Reading 518
12 The .NET Remoting System
521
Interprocess
Communications in the .NET Framework 521
.NET Remoting as a Better DCOM 522
What Is .NET Remoting? 525
Application Domains 526
Remotable
Objects 528
Marshaling Objects by Value 529
Marshaling Objects by Reference 531
Building
a Remote Service 534
Writing the Data Provider Class 535
Writing the Remote Service Component 540
Publishing the Remote Service Component 542
Server-Side Activation 545
Client-Side Activation 549
Choosing the Activation Mode That Fits 550
Memory Management 551
Calling
a Remote Service 552
Configuring the Caller 552
Writing the Client Component 554
Further
Reading 559
13 XML Web Services
561
The .NET
Framework Infrastructure for Web Services 562
The Simple Object Access Protocol (SOAP) 563
IIS Support 564
The WebService Class 566
Building
a .NET Web Service 568
Exposing Web Methods 568
Format of SOAP Messages for a Web Method 571
The Sales Report Web Service 574
Under the Hood of a Web Method Call 577
Building
a .NET Framework Web Service Client 581
The Proxy Class 582
Invoking a Web Service Through Script 586
.NET
Remoting vs. Web Services 589
Which Came First? 589
Web Service Issues 590
Further
Reading 593
14 XML on the Client
595
XML Support
in Internet Explorer 596
The Data Island (<xml>) Tag 596
The Role of the MSXML Parser 597
Other Ways to Embed XML Data 600
Creating Data Islands in ASP.NET 603
Embedding
.NET Framework Components in Internet Explorer 604
Building Windows Forms Controls for HTML Pages 605
A Data Display Custom Control 608
Putting
It All Together 613
Serializing DataSet Objects to Data Islands 615
From MSXML Documents to .NET XML Documents 616
Further
Reading 621
15 .NET Framework Application
Configuration 623
Configuration
Files 624
The XML Schema for Configuration Settings 624
Machine Configuration Files 626
Security Configuration Files 627
Application Configuration Files 628
Managing
Configuration Settings 629
The ConfigurationSettings Class 631
The AppSettingsReader Class 637
Creating
New Configuration Sections 638
Declaring a New Section 638
Types of Section Handlers 640
Under the Hood of Section Handlers 643
Customizing Attribute Names 645
Customizing
the XML Schema for Your Data 646
Creating a DataSet Section Handler 647
Implementing the DataSet Section Handler 653
Further
Reading 655
AFTERWORD 657
INDEX 661 |