This is a discussion on What is DiffGram? within the XML and SOAP forums, part of the Web Development category; Hi friends, Can any one expalin What is DiffGram? Thanks devarajan.V...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| ADO.NET introduced the DataSet class to support the disconnected, distributed data-access scenarios. With DataSet, the data retrieved from the database is cached in-memory, in addition to the constraints and relationships among the tables. When the ADO.NET DataSet is serialized as XML (for example, when returning a DataSet from an ASP.NET XML Web service method), the XML format used for DataSet serialization is known as DiffGram. |
| |||
| hi, The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. The other format is the standard XML layout, which includes a root node that is named after the DataSet and that includes as child subtrees the names of the embedded tables. Each subtree represents one record in the given table. All this information is available through the DiffGram format, and much more, as well. The key difference between the two XML formats lies in the ultimate goal for which they were designed. The ordinary XML serialization is mostly for persistence and local data storage, whereas the DiffGram format serves a slightly more ambitious purpose. The DiffGram is a format intended for network data exchange and .NET remoting. You can persist a DataSet object with or without schema information, and the resultant XML file is a simple snapshot of the data being stored in the DataSet. In fact, only the current value of each row and column is persisted. Each row's state (added, modified, deleted) is lost, along with any error information associated with it.
__________________ Venkat knowledge is Power |
| |||
| A DiffGram is an XML format that is used to identify current and original versions of data elements.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| DiffGram Examples The examples in this topic consist of DiffGrams that perform insert, update, and delete operations to the database. Before using the examples, note the following: * The examples use two tables (Cust and Ord) that must be created if you want to test the DiffGram examples: Code: Cust(CustomerID, CompanyName, ContactName) Ord(OrderID, CustomerID) Code: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:annotation>
<xsd:documentation>
Diffgram Customers/Orders Schema.
</xsd:documentation>
<xsd:appinfo>
<sql:relationship name="CustomersOrders"
parent="Cust"
parent-key="CustomerID"
child-key="CustomerID"
child="Ord"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="Customer" sql:relation="Cust">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="CompanyName" type="xsd:string"/>
<xsd:element name="ContactName" type="xsd:string"/>
<xsd:element name="Order" sql:relation="Ord" sql:relationship="CustomersOrders">
<xsd:complexType>
<xsd:attribute name="OrderID" type="xsd:int" sql:field="OrderID"/>
<xsd:attribute name="CustomerID" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="CustomerID" type="xsd:string" sql:field="CustomerID"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Deleting a record by using a DiffGram The DiffGram in this example deletes a customer (whose CustomerID is ALFKI) record from the Cust table and deletes the corresponding order record (whose OrderID is 1) from the Ord table. Code: <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:mapping-schema="DiffGramSchema.xml">
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DataInstance/>
<diffgr:before>
<Order diffgr:id="Order1"
msdata:rowOrder="0"
CustomerID="ALFKI"
OrderID="1"/>
<Customer diffgr:id="Customer1"
msdata:rowOrder="0"
CustomerID="ALFKI">
<CompanyName>Alfreds Futterkiste</CompanyName>
<ContactName>Maria Anders</ContactName>
</Customer>
</diffgr:before>
<msdata:errors/>
</diffgr:diffgram>
</ROOT>
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Inserting a record by using a DiffGram In this example, the DiffGram inserts a record in the Cust table and a record in the Ord table. Code: <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql"
sql:mapping-schema="DiffGramSchema.xml">
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DataInstance>
<Customer diffgr:id="Customer1" msdata:rowOrder="0"
diffgr:hasChanges="inserted" CustomerID="ALFKI">
<CompanyName>C3Company</CompanyName>
<ContactName>C3Contact</ContactName>
<Order diffgr:id="Order1"
msdata:rowOrder="0"
diffgr:hasChanges="inserted"
CustomerID="ALFKI" OrderID="1"/>
</Customer>
</DataInstance>
</diffgr:diffgram>
</ROOT>
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Updating an existing record by using a DiffGram In this example, the DiffGram updates customer information (CompanyName and ContactName) for customer ALFKI. Code: <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:mapping-schema="DiffGramSchema.xml">
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DataInstance>
<Customer diffgr:id="Customer1"
msdata:rowOrder="0" diffgr:hasChanges="modified"
CustomerID="ALFKI">
<CompanyName>Bottom Dollar Markets</CompanyName>
<ContactName>Antonio Moreno</ContactName>
</Customer>
</DataInstance>
<diffgr:before>
<Customer diffgr:id="Customer1"
msdata:rowOrder="0"
CustomerID="ALFKI">
<CompanyName>Alfreds Futterkiste</CompanyName>
<ContactName>Maria Anders</ContactName>
</Customer>
</diffgr:before>
</diffgr:diffgram>
</ROOT>
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Inserting, updating, and deleting records by using a DiffGram In this example, a relatively complex DiffGram is used to perform insert, update, and delete operations. Code: <ROOT xmlns:sql="urn:schemas-microsoft-com:xml-sql" sql:mapping-schema="DiffGramSchema.xml">
<diffgr:diffgram
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DataInstance>
<Customer diffgr:id="Customer2" msdata:rowOrder="1"
diffgr:hasChanges="modified"
CustomerID="ANATR">
<CompanyName>Bottom Dollar Markets</CompanyName>
<ContactName>Elizabeth Lincoln</ContactName>
<Order diffgr:id="Order2" msdata:rowOrder="1"
msdata:hiddenCustomerID="ANATR"
CustomerID="ANATR" OrderID="2"/>
</Customer>
<Customer diffgr:id="Customer3" msdata:rowOrder="2"
CustomerID="ANTON">
<CompanyName>Chop-suey Chinese</CompanyName>
<ContactName>Yang Wang</ContactName>
<Order diffgr:id="Order3" msdata:rowOrder="2"
msdata:hiddenCustomerID="ANTON"
CustomerID="ANTON" OrderID="3"/>
</Customer>
<Customer diffgr:id="Customer4" msdata:rowOrder="3"
diffgr:hasChanges="inserted"
CustomerID="AROUT">
<CompanyName>Around the Horn</CompanyName>
<ContactName>Thomas Hardy</ContactName>
<Order diffgr:id="Order4" msdata:rowOrder="3"
diffgr:hasChanges="inserted"
msdata:hiddenCustomerID="AROUT"
CustomerID="AROUT" OrderID="4"/>
</Customer>
</DataInstance>
<diffgr:before>
<Order diffgr:id="Order1" msdata:rowOrder="0"
msdata:hiddenCustomerID="ALFKI"
CustomerID="ALFKI" OrderID="1"/>
<Customer diffgr:id="Customer1" msdata:rowOrder="0"
CustomerID="ALFKI">
<CompanyName>Alfreds Futterkiste</CompanyName>
<ContactName>Maria Anders</ContactName>
</Customer>
<Customer diffgr:id="Customer2" msdata:rowOrder="1"
CustomerID="ANATR">
<CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
<ContactName>Ana Trujillo</ContactName>
</Customer>
</diffgr:before>
</diffgr:diffgram>
</ROOT> * In accordance with DiffGram processing logic, all the top-level elements in the <before> block map to corresponding tables, as described in the mapping schema. * The <before> block has an <Order> element (dffgr:id="Order1") and a <Customer> element (diffgr:id="Customer1") for which there is no corresponding element in the <DataInstance> block (with the same ID). This indicates a delete operation, and the records are deleted from the Cust and Ord tables. * The <before> block has a <Customer> element (diffgr:id="Customer2") for which there is a corresponding <Customer> element in the <DataInstance> block (with the same ID). The element in the <DataInstance> block specifies diffgr:hasChanges="modified". This is an update operation in which for customer ANATR, the CompanyName and ContactName information is updated in the Cust table using values that are specified in the <DataInstance> block. * The <DataInstance> block has a <Customer> element (diffgr:id="Customer3") and an <Order> element (diffgr:id="Order3"). Neither of these elements specify the diffgr:hasChanges attribute. Therefore, the DiffGram processing logic ignores these elements. * The <DataInstance> block has a <Customer> element (diffgr:id="Customer4") and an <Order> element (diffgr:id="Order4") for which there are no corresponding elements in the <before> block. These elements in the <DataInstance> block specify diffgr:hasChanges="inserted". Therefore, a new record is added in the Cust table and in the Ord table.
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| Applying updates by using a DiffGram with the diffgr arentID annotationThis example illustrates how the parentID annotation that is specified in the <before> block of the DiffGram is used in applying the updates. Code: <NewDataSet />
<diffgr:before>
<Order diffgr:id="Order1" msdata:rowOrder="0" OrderID="2" />
<Order diffgr:id="Order3" msdata:rowOrder="2" OrderID="4" />
<OrderDetail diffgr:id="OrderDetail1"
diffgr:parentId="Order1"
msdata:rowOrder="0"
ProductID="13"
OrderID="2" />
<OrderDetail diffgr:id="OrderDetail3"
diffgr:parentId="Order3"
ProductID="77"
OrderID="4"/>
</diffgr:before>
</diffgr:diffgram>
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Explain what a DiffGram is and a good use for one? | devarajan.v | XML and SOAP | 1 | 08-11-2007 12:28 AM |
| Explain what a diffgram is, and a good use for one? | prasath | ASP and ASP.NET Programming | 1 | 07-18-2007 07:00 AM |