SQLXML 3.0 Application Skills

Source: Internet
Author: User

1. Generate the schema file of xmlbulkload. You can use the following SQL statement.
Declare @ tablename varchar (100), @ result varchar (8000)

-- Table name
Set @ tablename = 'cc'

Set @ result = '<? XML version = "1.0" encoding = "gb2312"?>
<XSD: schema xmlns: XSD = "http://www.w3.org/2001/XMLSchema"
Xmlns: dt = "urn: Schemas-Microsoft-com: datatypes"
Xmlns: SQL = "urn: Schemas-Microsoft-com: mapping-schema">

<XSD: element name = "table" SQL: Relation = "'+ @ tablename +'">
<XSD: complextype>'

Select @ result = @ result +'
<XSD: attribute name = "'+ A. Name +'" '+
+ Case
When B. Name = 'int' then' type = "XSD: int "'
When B. Name = 'datetime' then' type = "XSD: datetime" SQL: ype = "datetime "'
When B. Name = 'image' then' type = "XSD: base64binary "'
Else 'Type = "XSD: string" 'end
+ Case when columnproperty (A. ID, A. Name, 'isidentity ') = 1 then' SQL: datatype = "uniqueidentifier" 'else' end
+ '/>'

From syscolumns
Left join policypes B on A. xtype = B. xusertype
Inner join sysobjects D on A. ID = D. id and D. xtype = 'U' and D. Status> = 0
Where D. Name = @ tablename
Order by A. ID

Set @ result = @ result +'
</XSD: complextype>
</XSD: Element>
</XSD: schema>'

Print @ result

2,

Generating xsds

In our previous article we saw how we can use xsds in conjunction with SQLXML. but how can we generate xsds rather than typing them separately. here are some simple steps to achieve the same using. net IDE.

Step 1:

Open an Visual Studio. NET project, and on the project menu, click Add new item.

Step 2:

In the Add new item dialog, In the templates pane, select XML schema and open.

Step 3:

From the View menu, click Server Explorer (or press CTRL + ALT + S) to open Server Explorer.

Step 4:

Expand servers, select <machine Name>, SQL servers, select <machine Name>, select pubs database and tables.

Step 5:

Drag and Drop the orders table on to the design surface.

Step 6:

We are done in generating the XSD. Now move to the XML tab. You can see an ouput as outlined.

Step 7:

Now we cannot use this XSD generated directly. we have to have a couple of modifications and have to remove some content to get the final version. I 've removed some parts of the code and you can view the final document version.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.