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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

.<strong>NET</strong> <strong>XML</strong> writers only ensure the well-<strong>for</strong>medness of each <strong>in</strong>dividual <strong>XML</strong> elementbe<strong>in</strong>g generated. Writers can <strong>in</strong> no way guarantee the well-<strong>for</strong>medness of the entiredocument and can do even less to validate a document aga<strong>in</strong>st a DTD or a schema.Although badly <strong>for</strong>med <strong>XML</strong> documents can only result from actual gross programm<strong>in</strong>gerrors, the need <strong>for</strong> an extra step of validation is often felt <strong>in</strong> production environments,especially when the creation of the document depends on a number of variable factorsand run-time conditions. For this reason, we've also exam<strong>in</strong>ed the key po<strong>in</strong>ts <strong>in</strong>volved<strong>in</strong> the design and implementation of a validat<strong>in</strong>g <strong>XML</strong> writer.This chapter also featured a few custom <strong>XML</strong>-driven writers. In this chapter, youlearned how to write str<strong>in</strong>g arrays, JPEG images, and DataTable objects to specific<strong>XML</strong> schemas. It goes without say<strong>in</strong>g that the techniques discussed here do notexhaust the options available <strong>in</strong> the .<strong>NET</strong> Framework <strong>for</strong> those tasks. For example, the<strong>XML</strong> serializer can sometimes be more effectively employed to obta<strong>in</strong> the same results.(<strong>XML</strong> serializers are covered <strong>in</strong> Chapter 11.)These examples were provided with a double goal: to show one way to solve aproblem, and to demonstrate custom <strong>XML</strong> writers. As a general guidel<strong>in</strong>e, bear <strong>in</strong> m<strong>in</strong>dthat the more specific an <strong>XML</strong>-based <strong>for</strong>mat is, the more a specialized writer class canhelp. The key advantage of a writer class is perhaps not so much raw per<strong>for</strong>mancesav<strong>in</strong>gs but the resultant elegance, reusability, and efficiency of the design.We've also looked at an <strong>in</strong>termediate level of <strong>XML</strong> parser that falls somewhere betweenstream<strong>in</strong>g parsers such as readers and <strong>XML</strong> DOM. <strong>XML</strong> readers are great <strong>for</strong> pars<strong>in</strong>g<strong>XML</strong> documents, but they work <strong>in</strong> a read-only way. <strong>XML</strong> DOM parsers, on the otherhand, make updat<strong>in</strong>g documents a snap—but only after the documents have been fullyloaded <strong>in</strong> memory. The XmlTextReadWriter class <strong>in</strong>corporates a reader and a writerand coord<strong>in</strong>ates their <strong>in</strong>dependent activity through a simple new API. As a result, youcan parse a document one node at a time while ma<strong>in</strong>ta<strong>in</strong><strong>in</strong>g the ability to add, update,or delete nodes. The new class is not the cure-all <strong>for</strong> any <strong>XML</strong> pa<strong>in</strong>s, but it can be an<strong>in</strong>terest<strong>in</strong>g option <strong>in</strong> some situations.In Chapter 5, we'll exam<strong>in</strong>e the <strong>XML</strong> DOM classes that you must use when fullread/write access to <strong>XML</strong> documents is critical and when the ability to per<strong>for</strong>m searchestakes precedence over the memory footpr<strong>in</strong>t.Further Read<strong>in</strong>gThis chapter touches on a number of topics that you might want to know more about.Some are <strong>XML</strong>-related, but not so much .<strong>NET</strong>-related as to f<strong>in</strong>d an ideal place <strong>for</strong>discussion here. Some are not really <strong>XML</strong>-related but def<strong>in</strong>itely belong to the .<strong>NET</strong>Framework and, as such, deserve at least a reference here.One topic we spent a lot of time on <strong>in</strong> this chapter is <strong>XML</strong> namespaces and qualifiednames. The official site where the specification can be found ishttp://www.w3.org/TR/REC-xml-names. In Chapter 3, I covered <strong>XML</strong> validation and thevarious schema <strong>in</strong>volved <strong>in</strong> the process. If you th<strong>in</strong>k you need an <strong>XML</strong> crash coursefrom a higher, non-.<strong>NET</strong>-Framework-related perspective, I can recommend two books.One is Essential <strong>XML</strong>, by Don Box, John Lam, and Aaron Skonnard (Addison-Wesley,2000). This reference is great if you need to get the gist of <strong>XML</strong> <strong>in</strong> a plat<strong>for</strong>m<strong>in</strong>dependentand language-<strong>in</strong>dependent context. Otherwise, look at the <strong>XML</strong><strong>Programm<strong>in</strong>g</strong> Core Reference, by R. Allen Wyke, Sultan Rehman, Brad Leupen, andAsh Rofail (<strong>Microsoft</strong> Press, 2002), <strong>for</strong> more development-related considerations andtips.A great source <strong>for</strong> learn<strong>in</strong>g about underdocumented features and tricks of the .<strong>NET</strong>Framework is certa<strong>in</strong>ly Jeffrey Richter's most recent book, <strong>Applied</strong> .<strong>NET</strong> Framework<strong>Programm<strong>in</strong>g</strong> (<strong>Microsoft</strong> Press, 2002). This book is a gold m<strong>in</strong>e <strong>for</strong> all that bor<strong>in</strong>g stuff166

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

Saved successfully!

Ooh no, something went wrong!