TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
XSD in SQL Server
Venkatesan Jayakantham
May 03, 2012
7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
XSD in SQL Server
XML validation using XSD in SQL Server:
To acheive the validation process, we will be utilising the option of Regex pattern.
Here is the list of steps to be done in XSD implementation on the XML.
1. Check for the existing XML Schema collection -> Drop it.
2. Create XSD and bind it with XML Schema Collection
3. Create XML of type XML Schema Collection
4. If it binds, it indicates the XML is satisfying the condition specified by the XSD.
Regex pattern, I've provided is "The username and password can contain any number of special characters and any number of integers but it should not contain the special character - and / in it.
Let's move on to the querying part.
IF EXISTS(
SELECT * FROM sys.xml_schema_collections
WHERE name = 'StringPattern'
) BEGIN
DROP XML SCHEMA COLLECTION ValidationPattern
END
GO
-------------------------------------------------------------
create XML SCHEMA COLLECTION ValidationPattern AS '
'
-------------------------------------------------------------
GO
DECLARE @x XML(StringPattern)
SET @x = '
AC78HJGVHJ35
AC78HJGVHJ35
'
SELECT @x
-- This will give the output
-----------------------------------------------
DECLARE @x XML(StringPattern)
SET @x = '
AC78HJGVH/J35
AC78HJGVHJ35
'
SELECT @x
------This won't give the output
--------------------------------------------------
Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech
XSD in SQL Server
Next Recommended Reading
Difference between SQL Server 2008 and SQL Server 2012