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.

xsi:noNamespaceSchemaLocation="address.xsd"country="Italy">One <strong>Microsoft</strong> Way1RedmondWA98052The schema can be tied to a namespace by us<strong>in</strong>g the schemaLocation attribute, asshown here:One <strong>Microsoft</strong> Way1RedmondWA98052In this case, the XSD (address1.xsd) must be slightly modified by add<strong>in</strong>g atargetNamespace attribute and sett<strong>in</strong>g an xmlns attribute to the target namespace URI,as follows:Needless to say, the target namespace must match the designated namespace URI <strong>in</strong>the source document.Complex Type InheritanceWith complex types, you simply def<strong>in</strong>e <strong>XML</strong> data structures that are <strong>in</strong> no logical waydifferent from classes of object-oriented languages such as C# or Java. One keyfeature of those languages is the ability to derive new data types from exist<strong>in</strong>g classes.The same k<strong>in</strong>d of <strong>in</strong>heritance can be achieved with <strong>XML</strong> schemas. To demonstrate,we'll build a new address type that, as <strong>in</strong> many European countries, takes <strong>in</strong>to accountalso the prov<strong>in</strong>ce.The address.xsd schema considered up to now conta<strong>in</strong>s more than just the def<strong>in</strong>ition ofa complex type—it also conta<strong>in</strong>s a global element that will be <strong>in</strong>cluded <strong>in</strong> any compliantdocument as an <strong>in</strong>stance of the type. Let's first create a base class <strong>for</strong> the schema andname it xaddress.xsd, as shown <strong>in</strong> the follow<strong>in</strong>g code. The new file differs from theearlier version <strong>in</strong> only one aspect: it now lacks the global element declaration.93

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

Saved successfully!

Ooh no, something went wrong!