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.

Table 2-4: Types of Nodes <strong>in</strong> the XmlNodeType EnumerationNode TypeDescriptionSignificantWhitespace Represents a significant white space characterbetween markup text <strong>in</strong> a mixed-content model orwhite space with<strong>in</strong> the scope ofxml:space="preserve".TextRepresents the text content of an element.WhitespaceRepresents an <strong>in</strong>significant space between markuptext.XmlDeclaration Represents the <strong>XML</strong> declaration node.XmlDeclaration must be the first node <strong>in</strong> thedocument and can't have children. The node canhave attributes that provide version and encod<strong>in</strong>g<strong>in</strong><strong>for</strong>mation.Table 2-4 <strong>in</strong>cludes all the possible types of nodes found with<strong>in</strong> the body of an <strong>XML</strong>document—at least when the document is parsed through a .<strong>NET</strong> <strong>XML</strong> reader. Noticethat the <strong>XML</strong> element that is normally perceived as be<strong>in</strong>g the node—that is, marked uptext—is said to be an element node. Attributes, comments, and even process<strong>in</strong>g<strong>in</strong>structions are just other types of nodes. In light of this, when you move from one nodeto the next, you are not necessarily mov<strong>in</strong>g between nodes of the same type.A lot of <strong>XML</strong> documents beg<strong>in</strong> with several tags that do not represent any data content.The reader's MoveToContent method lets you skip all the head<strong>in</strong>g <strong>in</strong><strong>for</strong>mation andposition the po<strong>in</strong>ter directly <strong>in</strong> the first content node. In do<strong>in</strong>g so, the method skips overthe follow<strong>in</strong>g node types: Process<strong>in</strong>gInstruction, DocumentType, Comment,Whitespace, and SignificantWhitespace.Specialized Reader ClassesThe XmlReader class def<strong>in</strong>es only the clauses and appendices <strong>in</strong> the contract that.<strong>NET</strong> <strong>XML</strong> applications sign with the actual parser class. Because XmlReader is anabstract class, you'll use it <strong>in</strong> your code only as a reference type when type cast<strong>in</strong>g isneeded. In lieu of XmlReader, you can use any of its derived classes already def<strong>in</strong>ed <strong>in</strong>the .<strong>NET</strong> Framework. In addition, you can use any other custom reader class that thirdpartyvendors, or you yourself, might have written. All of these reader classes share theprogramm<strong>in</strong>g <strong>in</strong>terface with XmlReader, however, and provide an actual, albeit custom,implementation <strong>for</strong> each of the methods and properties listed <strong>in</strong> Table 2-1, on page 27,and Table 2-3, on page 30.Implementations of the XmlReader class extend the base class and vary <strong>in</strong> their designto support different scenarios. The .<strong>NET</strong> Framework supplies the follow<strong>in</strong>g readerclasses:• XmlTextReader Extremely fast; the reader ensures that the <strong>XML</strong> sourceis well-<strong>for</strong>med but neither validates it aga<strong>in</strong>st a schema or a DTD norresolves any embedded entity.• XmlValidat<strong>in</strong>gReader An <strong>XML</strong> reader that can validate the source us<strong>in</strong>ga DTD, an <strong>XML</strong>-Data Reduced (XDR) schema, and an <strong>XML</strong> SchemaDef<strong>in</strong>ition (XSD). In addition, the reader is capable of expand<strong>in</strong>g entitiesand also supports default attributes as def<strong>in</strong>ed <strong>in</strong> the DTD or schema.• XmlNodeReader The reader specializes <strong>in</strong> pars<strong>in</strong>g <strong>XML</strong> data from an<strong>XML</strong> Document Object Model (<strong>XML</strong> DOM) subtree and does not supportvalidation.In the next section, we'll exam<strong>in</strong>e the XmlTextReader class—probably the mostfrequently used .<strong>NET</strong> reader class. Validat<strong>in</strong>g readers will be covered <strong>in</strong> Chapter 3;27

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

Saved successfully!

Ooh no, something went wrong!