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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 3-6: Mapp<strong>in</strong>g Between XSD and .<strong>NET</strong> TypesXSD Type .<strong>NET</strong> Type Description<strong>in</strong>tegerQName System.Xml.XmlQualifiedName An <strong>XML</strong> qualifiednameshort System.Int16 16-bit signed <strong>in</strong>tegerstr<strong>in</strong>g System.Str<strong>in</strong>g A str<strong>in</strong>g typetime System.DateTime An <strong>in</strong>stant <strong>in</strong> timetimePeriod System.DateTime A period of timetoken System.Str<strong>in</strong>g Normalized str<strong>in</strong>g withlead<strong>in</strong>g and trail<strong>in</strong>gwhite spaces removedunsignedByte System.Byte 8-bit unsigned <strong>in</strong>tegerunsignedInt System.UInt32 32-bit unsigned <strong>in</strong>tegerunsignedLong System.UInt64 64-bit unsigned <strong>in</strong>tegerunsignedShort System.UInt16 16-bit unsigned <strong>in</strong>tegerThe schema compiler is a piece of code that translates between XSD types and thetype system of a particular plat<strong>for</strong>m. In the .<strong>NET</strong> Framework, the schema compilercompiles XSD <strong>in</strong>to an XmlSchema object that exposes the schema <strong>in</strong><strong>for</strong>mation throughmethods and properties.Effective serialization between XSD and b<strong>in</strong>ary classes on a given plat<strong>for</strong>m is a featurewith tremendous potential. It could supersede today's <strong>XML</strong> pars<strong>in</strong>g by automaticallycreat<strong>in</strong>g an <strong>in</strong>stance of a class <strong>in</strong>stead of creat<strong>in</strong>g a generic and unwieldy <strong>XML</strong> DOM orsimply pass<strong>in</strong>g raw data to the application. In the .<strong>NET</strong> Framework, <strong>XML</strong> serialization isaccomplished us<strong>in</strong>g the XmlSerializer class and exploit<strong>in</strong>g the services of the <strong>XML</strong>Schema def<strong>in</strong>ition tool (xsd.exe). I'll cover <strong>XML</strong> serialization extensively <strong>in</strong> Chapter 11.NoteThe <strong>XML</strong> Schema def<strong>in</strong>ition tool (xsd.exe) is an executableavailable with the .<strong>NET</strong> Framework SDK. You'll f<strong>in</strong>d it <strong>in</strong> the BINsubdirectory of the .<strong>NET</strong> Framework <strong>in</strong>stallation path. Normally, thispath is C:\Program Files\<strong>Microsoft</strong> Visual Studio.<strong>NET</strong>\FrameworkSDK.Among other th<strong>in</strong>gs, xsd.exe can generate a C# or Visual Basicclass from an XSD file and <strong>in</strong>fer an XSD from a source <strong>XML</strong> file.This tool is also responsible <strong>for</strong> all the XSD-related magic per<strong>for</strong>medby Visual Studio .<strong>NET</strong>.Def<strong>in</strong><strong>in</strong>g an XSD SchemaYou have three options when creat<strong>in</strong>g an XSD schema. You can write it manually bycomb<strong>in</strong><strong>in</strong>g the various tags def<strong>in</strong>ed by the <strong>XML</strong> Schema specification. A more effectiveoption is represented by Visual Studio .<strong>NET</strong>, which provides a visual editor <strong>for</strong> XSD fileswith full IntelliSense support. The third option is based on the <strong>XML</strong> Schema def<strong>in</strong>itiontool (xsd.exe) mentioned <strong>in</strong> the previous section, which can <strong>in</strong>fer the underly<strong>in</strong>g schemafrom any well-<strong>for</strong>med <strong>XML</strong> document.Of these options, the first is certa<strong>in</strong>ly the hardest to code and the one that you willprobably use less frequently. It also happens to be the most useful tool <strong>for</strong> ga<strong>in</strong><strong>in</strong>g an90

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

Saved successfully!

Ooh no, something went wrong!