IT Community - Software Programming, Web Development and Technical Support

What is DiffGram?

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...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > XML and SOAP

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-25-2007, 06:06 AM
devarajan.v devarajan.v is offline
D-Web Master
 
Join Date: May 2007
Posts: 382
devarajan.v is on a distinguished road
Question What is DiffGram?

Hi friends,

Can any one expalin What is DiffGram?


Thanks
devarajan.V
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 03:29 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Default Re: What is DiffGram?

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-11-2007, 01:39 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: What is 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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-13-2007, 12:12 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Default Re: What is DiffGram?

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-13-2007, 12:38 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: What is DiffGram?

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)
* Most of the examples in this topic use the following XSD Schema:

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>
Save this schema as DiffGramSchema.xml in the same folder where you save other files used in the examples.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-13-2007, 12:40 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: What is DiffGram?

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>
In the <before> block, there is an <Order> element (diffgr:id="Order1") and a <Customer> element (diffgr:id="Customer1"). These elements represent existing records in the database. The <DataInstance> element does not have the corresponding records (with the same diffgr:id). This indicates a delete operation.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-13-2007, 12:41 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Cool Re: What is DiffGram?

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>
In this DiffGram the <before> block is not specified (no existing database records identified). There are two record instances (identified by the <Customer> and <Order> elements in the <DataInstance> block) that map to Cust and Ord tables, respectively. Both of these elements specify the diffgr:hasChanges attribute (hasChanges="inserted"). This indicates an insert operation. In this DiffGram, if you specify hasChanges="modified", you are indicating that you want to modify a record that does not exist, which results in an error.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-13-2007, 12:43 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Cool Re: What is DiffGram?

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>
The <before> block includes a <Customer> element (diffgr:id="Customer1"). The <DataInstance> block includes the corresponding <Customer> element with same id. The <customer> element in the <NewDataSet> also specifies diffgr:hasChanges="modified". This indicates an update operation, and the customer record in the Cust table is updated accordingly. Note that if the diffgr:hasChanges attribute is not specified, the DiffGram processing logic ignores this element and no updates are performed.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 10-13-2007, 12:45 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: What is DiffGram?

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>
The DiffGram logic processes this DiffGram as follows:

* 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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 10-13-2007, 12:47 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Smile Re: What is DiffGram?

Applying updates by using a DiffGram with the diffgrarentID annotation

This 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>
This DiffGram specifies a delete operation because there is only a <before> block. In the DiffGram, the parentID annotation is used to specify a parent-child relationship between the orders and order details. When SQLXML deletes the records, it deletes records from the child table that is identified by this relationship and then deletes the records from the corresponding parent table.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 02:13 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0