SQL Server XML splitting example

Source: Internet
Author: User
Tags xml example xquery

Use the Xquery profiling element to complete XML decomposition. Remember, Xpath is a subset of Xquery. Xquery uses Xpath to describe the document part of an XML file. Use expressions such as "For, Let, Where, Order By, Return" to supplement the description, or use FLWOR (abbreviation of the preceding five words) to simplify the description. Xquery does not support update operations and full-text search. These two functions may be available in the future. However, Xquery is only a query language.
XML example

 1 <sample1>  
2  <company>TheRealLife</company>
3  <company>TheRealLife2</company>
4  <city>Miami</city>
5  <year-founded>1998</ year-founded>
6  <industry>software</industry>
7  </sample1>
8

Example of calling a stored procedure

 

  1 declare @m as xml; 
2 set @m = ' <sample1>
3 <company>TheRealLife</company>
4 <company>TheRealLife2</company>
5 <city>Miami</city>
6 <year-founded>1998</year-founded>
7 <industry>software</industry>
8 </sample1>'
9 exec dbo.XMLShred @d = @m;
10 Result set1:
11 TheRealLife TheRealLife2
12 Result set2:
13 <company>TheRealLife</company>
14 <company>TheRealLife2</company>
15

 

Stored Procedure decomposition example

 

 1 create proc dbo.XMLShred (@d as XML) 
2   AS
3   select @d.query('
4   for $step in /sample1/company
5   return string($step)
6   ')
7   select @d.query ('/sample1/company')
8   return 0;
9

 

Considering that the T-SQL has limited processing capabilities for complex XML operations, you can choose to use CLR stored procedures. This method is mainly based on the stored procedures implemented using Microsoft. NET Framework CLR and stored procedures that support CLR programming, such as C # Or VB. NET. Remember, in this structure, you must be able to deploy the Assembly on the physical SQL Server. Whether this is a problem depends entirely on whether the production server is locked. In addition, the Assembly must be included in the restoration scope during system restoration. Therefore, you must make a careful plan to correctly handle the disaster recovery, measurable and other impacts.

 

 

Related Article

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.