BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
SQL XML
SQLXML - .NET Updategrams
.NET XPath Queries
SQLXML - Mapping Relationships To XML
SQLXML - Mapping .NET Schemas
.NET & OPENXML
.NET Parameterized Templates
SQLXML - Raw mode
SQLXML - FOR XML mode
Automate saving options from ADO into an XML format
Microsoft's dataselect functionality in the XML DSO
VB/ADO to DataIsland
Inserting nodes: String Load or Dom Load?
WebDAVExplorer
XML-based Internet RPC (XIR)
XDO
Translating an ADO recordset's XML to another XML vocab
How to find distinct values from XML (Muenchian Technique)
Converting to DateTime format in SQL
Filtering unique values
Passing stored procedure a list of complete zipcodes to validate
<< SEO
System.XML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :260

 

Annotating .NET Updategrams

In certain cases, we have to provide more information than just the elements in the <before> and <after> sections for the SQLXML engine to compose the correct SQL statement. When we need to set a database field to NULL for example, simply omitting the corresponding element or attribute from the Updategram will not set the field to NULL. Instead the value in the database remains unchanged because leaving the field we need to set out of the Updategram only causes the value to be excluded from the generated SQL statement.

To let SQLXML know that we want to set a field to NULL, we need to define which value in the Updategram represents NULL in the database and include it in the updategram. We define how NULL is represented in the updategram, by adding the nullvalue annotation to the <sync> element. Now we can reference the defined nullvalue in the updategram anywhere we need compare against or set something to NULL. The following snippet demonstrates the use of the nullvalue attribute to assign a value to WebSite field that was previously NULL:

<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">

  <updg:sync >

    <updg:before updg:nullvalue="(null)">

      <Supplier>

        <SupplierID>12345</SupplierID>

        <WebSite>(null)</WebSite>

      </Supplier>

    </updg:before>

    <updg:after>

      <Supplier>

        <SupplierID>12345</SupplierID>

        <WebSite>http://www.yoursupplier.com</WebSite>

      </Supplier>

    </updg:after>

  </updg:sync>

</ROOT>

Other situations where we need to annotate Updategrams, are retrieving automatically generated IDENTITY values and GUIDs and updates of designated key fields. Table 15.7 lists all annotation attributes for recognized by SQLXML. Section 15.3.4.4 discusses all issues around identity inserts in more detail.

1.7            Annotation to updategrams provide meta information about the XML document beyond what is in the mapping schema. The updategram processing engine reads these annotations to generate the translate the updategrams to SQL statements correctly.

Annotation

Valid On

Description

at-identity

Inserted element or attribute

Defines a place holder to receive SQL Server generated INDENTITY values. Other elements and attributes can reference the value by the placeholder.

guid

Inserted element

Defines a place holder for a GUID generated when the updategram executes.

id

Inserted element

Helps the updategram engine to track corresponding elements in the before and after sections of a sync block. Corresponding elements must carry the same id if the mapping schema does not identify the key-fields or if the updategram modifies a key field.

nullvalue

<sync>, <header>

Identifies the character sequence the update processor will treat as NULL.

returnid

<after>

Lists the SQL Server generated identities to return. The listed identifiers must match identity placeholders defined in at-identity annotations.

Parameterized Updategrams

I mentioned that an Updategram is nothing but a special Template format. This implies that we can also work with parameters in Updategrams just like we can in Templates. The parameters are defined in the optional <header> section and can be referenced throughout the rest of the Updategram, as shown in the following example:

<ROOT xmlns:updg="urn:schemas-microsoft-com:xml-updategram">

  <updg:header>

    <updg:param name="ID" />

    <updg:param name="Name" />

  </updg:header>

  <updg:sync>

    <updg:after>

      <Supplier>

        <SupplierID>$ID</SupplierID>

        <SupplierName>$Name</SupplierName>

      </Supplier>

    </updg:after>

  </updg:sync>

</ROOT>

Parameterized Updategrams are useful in situations where we do not want to compose an Updategram on the fly or when we want to maintain a higher level of control over an Updategram’s content. Another benefit of parameterized templates is the fact that we can keep the templates outside the compiled code, for example in resource DLLs or regular files, so we can perform minor bug fixes or simple updates without the need to recompile any code.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C

View all Jobs (Add yours)
View all CV (Add yours)



masks
swimming pool builder
free conference call
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP