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>for</strong> def<strong>in</strong><strong>in</strong>g the structure of <strong>XML</strong> data. Second, it is the newest schema technology, andas such, has been built specifically to fix bugs and flaws <strong>in</strong> the other schemas (mostlyproblems with DTDs). And remember, more than an alternative schema technology,XDR is <strong>Microsoft</strong>'s implementation of an early work<strong>in</strong>g draft of the <strong>XML</strong> Schemaspecification.Although no developer can seriously th<strong>in</strong>k of deny<strong>in</strong>g the significance of <strong>XML</strong>, manyperceive <strong>XML</strong> as a sort of extraneous entity that lies outside the ma<strong>in</strong> body of the codeand that must be <strong>in</strong>tegrated through dist<strong>in</strong>ct objects. <strong>XML</strong> parsers process str<strong>in</strong>gs madeof text and markup and come up with b<strong>in</strong>ary representations of that content. When youtry to <strong>in</strong>tegrate this with the rest of the caller program, you must effectively trans<strong>for</strong>mtext content <strong>in</strong>to more specific data types.The same issue arises <strong>in</strong> the other direction. To export your b<strong>in</strong>ary objects to <strong>XML</strong>, youper<strong>for</strong>m a k<strong>in</strong>d of text serialization that looks more like a normalization of <strong>in</strong>volved typeswith subsequent loss of type <strong>in</strong><strong>for</strong>mation. You shouldn't be surprised by this <strong>in</strong><strong>for</strong>mationloss, because <strong>XML</strong> doesn't have a type system.DTD is a <strong>for</strong>mat designed to describe the structure and the contents of a documentrather than to endow <strong>XML</strong> with an effective type system. XDR, on the other hand,<strong>in</strong>troduces the concept of typed attributes. XSD th<strong>in</strong>ks a little bigger. Not only does itre<strong>in</strong><strong>for</strong>ce the importance of typed attributes, but it also dist<strong>in</strong>guishes between simpleand complex types, simplifies type <strong>in</strong>heritance, and exposes a full-blown and official<strong>XML</strong> type system.The .<strong>NET</strong> Framework has been designed around <strong>XML</strong> standards, <strong>in</strong>clud<strong>in</strong>g XSD.Although the .<strong>NET</strong> Framework type system is a separate entity from the <strong>XML</strong> typesystem, a conversion API does exist that greatly simplifies software <strong>in</strong>teraction through<strong>in</strong>tegration technologies such as SOAP and Web services.What Is a Schema, Anyway?A schema is an <strong>XML</strong> file (with typical extension .xsd) that describes the syntax andsemantics of <strong>XML</strong> documents us<strong>in</strong>g a standard <strong>XML</strong> syntax. An <strong>XML</strong> schema specifiesthe content constra<strong>in</strong>ts and the vocabulary that compliant documents mustaccommodate. For example, compliant documents must fulfill any dependenciesbetween nodes, assign attributes the correct type, and give child nodes the exactcard<strong>in</strong>ality.The <strong>XML</strong> Schema specification is articulated <strong>in</strong>to two dist<strong>in</strong>ct parts. Part I conta<strong>in</strong>s thedef<strong>in</strong>ition of a grammar <strong>for</strong> complex types—that is, composite <strong>XML</strong> elements. Part IIdescribes a set of primitive types—the <strong>XML</strong> type system—plus a grammar <strong>for</strong> creat<strong>in</strong>gnew primitive types, said to be simple types. New types are def<strong>in</strong>ed <strong>in</strong> terms of exist<strong>in</strong>gtypes.An <strong>XML</strong> schema also supports rather advanced and object-oriented concepts such astype <strong>in</strong>heritance. In the .<strong>NET</strong> Framework, the SOM provides a suite of classes held <strong>in</strong>the System.Xml.Schema namespace to read a schema from an XSD file. Theseclasses also enable you to programmatically create a schema that can be eithercompiled <strong>in</strong> memory or written to a disk file.Simple and Complex Types<strong>XML</strong> simple types consist of pla<strong>in</strong> text and don't conta<strong>in</strong> any other elements. Examplesof simple types are str<strong>in</strong>g, date, and various flavors of numbers (long, double, and<strong>in</strong>teger). <strong>XML</strong> complex types can <strong>in</strong>clude child elements and attributes. In practice, acomplex type is always rendered as an <strong>XML</strong> subtree. A complex type can beassociated only with an <strong>XML</strong> element node, whereas a simple type applies to bothelements and attributes.The diagram <strong>in</strong> Figure 3-7 illustrates the structure of the XSD type system.86

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

Saved successfully!

Ooh no, something went wrong!