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.

provided way to serialize ADO.<strong>NET</strong> objects <strong>in</strong> b<strong>in</strong>ary <strong>for</strong>mats. We'll return to this topic <strong>in</strong>the section "Custom B<strong>in</strong>ary Serialization," on page 424.The DataSet Object's Embedded API <strong>for</strong> <strong>XML</strong>Table 9-1 presents the DataSet object methods you can use to work with <strong>XML</strong>, both <strong>in</strong>read<strong>in</strong>g and <strong>in</strong> writ<strong>in</strong>g. This list represents the DataSet object's <strong>in</strong>ternal <strong>XML</strong> API, whichis at the foundation of the serialization and deserialization processes <strong>for</strong> the object.Table 9-1: The DataSet Object's Embedded Serialization APIMethodGetXmlGetXmlSchemaReadXmlReadXmlSchemaWriteXmlWriteXmlSchemaDescriptionReturns an <strong>XML</strong> representation of the data currentlystored <strong>in</strong> the DataSet object. No schema <strong>in</strong><strong>for</strong>mation is<strong>in</strong>cluded.Returns a str<strong>in</strong>g that represents the <strong>XML</strong> schema<strong>in</strong><strong>for</strong>mation <strong>for</strong> the data currently stored <strong>in</strong> the object.Populates the DataSet object with the specified <strong>XML</strong>data read from a stream or a file. Dur<strong>in</strong>g the process,schema <strong>in</strong><strong>for</strong>mation is read or <strong>in</strong>ferred from the data.Loads the specified <strong>XML</strong> schema <strong>in</strong><strong>for</strong>mation <strong>in</strong>to thecurrent DataSet object.Writes out the <strong>XML</strong> data, and optionally the schema,that represents the DataSet object to a storagemedium—that is, a stream or a file.Writes out a str<strong>in</strong>g that represents the <strong>XML</strong> schema<strong>in</strong><strong>for</strong>mation <strong>for</strong> the DataSet object. Can write to astream or a file.Note that GetXml returns a str<strong>in</strong>g that conta<strong>in</strong>s <strong>XML</strong> data. As such, it requires moreoverhead than simply us<strong>in</strong>g WriteXml to write <strong>XML</strong> to a file. You should not use GetXmland GetXmlSchema unless you really need to obta<strong>in</strong> the DataSet representation orschema as dist<strong>in</strong>ct str<strong>in</strong>gs <strong>for</strong> <strong>in</strong>-memory manipulation. The GetXmlSchema methodreturns the DataSet object's <strong>XML</strong> Schema Def<strong>in</strong>ition (XSD) schema; there is no way toobta<strong>in</strong> the DataSet object's <strong>XML</strong>-Data Reduced (XDR) schema.As Table 9-1 shows, when you're work<strong>in</strong>g with DataSet and <strong>XML</strong>, you can managedata and schema <strong>in</strong><strong>for</strong>mation as dist<strong>in</strong>ct entities. You can take the <strong>XML</strong> schema out ofthe object and use it as a str<strong>in</strong>g. Alternatively, you could write the schema to a disk fileor load it <strong>in</strong>to an empty DataSet object. Alongside the methods listed <strong>in</strong> Table 9-1, theDataSet object also features two <strong>XML</strong>-related properties: Namespace and Prefix.Namespace specifies the <strong>XML</strong> namespace used to scope <strong>XML</strong> attributes and elementswhen you read them <strong>in</strong>to a DataSet object. The prefix to alias the namespace is stored<strong>in</strong> the Prefix property. The namespace can't be set if the DataSet object alreadyconta<strong>in</strong>s data.Writ<strong>in</strong>g Data as <strong>XML</strong>The contents of a DataSet object can be serialized as <strong>XML</strong> <strong>in</strong> two ways that I'll callstateless and stateful. Although these expressions are not common throughout theADO.<strong>NET</strong> documentation, I believe that they capture the gist of the two <strong>XML</strong> schemasthat can be used to persist a DataSet object's contents. A stateless representationtakes a snapshot of the current <strong>in</strong>stance of the data and renders it accord<strong>in</strong>g to aparticular <strong>XML</strong> schema (def<strong>in</strong>ed <strong>in</strong> Chapter 1 as the ADO.<strong>NET</strong> normal <strong>for</strong>m). A statefulrepresentation, on the other hand, conta<strong>in</strong>s the history of the data <strong>in</strong> the object and326

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

Saved successfully!

Ooh no, something went wrong!