We're working hard on the next version of Developer Fusion. Let us know what you think
we should be up to!
Members
Technology Zones
Articles
Hosted By
Info
|
Rated
Read 18,929 times
Contents
Related Categories
What's new in System.Xml 2.0 - Introduction, XML readers & writers
Introduction, XML readers & writers
This article was originally published on DNJ Online
While there have been many improvements and
new features added to ADO.NET, the changes going on in the XML-related
classes in version 2.0 have been even more dramatic. Through the XML
InfoSet model defined by the World Wide Web Consortium (W3C), XML is
evolving to become a universal data access technology that can
represent both structured rowset data and hierarchical and unstructured
information. As this view of XML, and the associated standards, have
been emerging, so the classes in the System.Xml and its subsidiary
namespaces have been changing to better accommodate the needs of
developers and provide the best possible performance. The what follows
is a brief overview of these changes and the associated techniques that
the new classes enable when working with XML.
XML Readers and Writers
The
XmlReader and XmlWriter classes in the System.Xml namespace are the
common base classes that provide streaming access for reading and
writing XML documents. In version 1.x, these classes are
abstract, and you use the concrete classes such as XmlTextReader and
XmlTextWriter to perform XML data access. However, in version 2.0, the
approach has changed. Instead, you use the new XmlReaderSettings and
XmlWriterSettings classes to define the behavior you want with regards
to validation, white-space handling, indenting and so forth, and then
generate instances of the XmlReader and XmlWriter classes that exhibit
the required behavior.
This approach offers several advantages. It makes it is easier to
pass instances of the classes to other routines in your applications in
such a way that the consumer can add new behavior but not remove
existing behavior. It also allows you to use them as streaming
producer/consumer instances to pipeline XML between tiers of an
application. And finally, it allows the Framework to make appropriate
optimizations, such as not including validation code where this is not
required, while supporting future extensibility of the classes.
The XmlReader also exhibits another useful new feature in that it
can perform validation directly, without you having to create an
XmlValidatingReader from it (as is the case in version 1.x).
Furthermore, the XmlReader and XmlWriter now support all the CLR data
types directly, allowing you read values from an XmlReader as typed
data, and pass typed data instances directly to the XmlWriter, as shown
below.
Alex spent most of his earlier working life as a technical salesman, and has had a love-hate relationship with computers that goes way back to the Sinclair Z80 and the Oric Atmos. In 1996 he retired from full-time work to concentrate on writing and developing in the fast-growing arena of the Web. This coincided with the release of Microsoft ASP 1.0, and since then he has been involved almost exclusively in that area.
Alex has written or contributed to over 40 books on Web technologies for Wrox Press, Sams Publishing, APress! and Addison Wesley, predominantly on Microsoft ASP and ASP.NET, XML, and mobile device support. He has also contributed more than 20 articles to ASPToday, plus several to other ASP-related Web resources sites such as DevX and 15seconds.com.
He has presented sessions about Web technologies at four Wrox conferences, two ASPDevCon conferences, as well as Microsoft's PDC, Tech-Ed, ASP.NET Connections and VS-Live conferences. He has also conducted training sessions for McKesson HBOC, BMS Limited, and other local companies and developers on ASP.NET and XML. In addition he has provided talks and demonstrations for local Dot Net User Groups, DDG-UK, and even for user groups in exotic locations such as Vienna.
Alex has been awarded MVP status by Microsoft, and is also a member of the CodeWise community, the ASP.NET Insiders group, and the INETA Speaker Bureau. In what spare time is left, he runs his own software and consultancy company Stonebroom Ltd.
Comments
|
Search
Code Samples
New Members
|