Michael Rys

Musings on XML, XQuery and more...

<July 2008>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789


Navigation

Papers

SQL Server XML Whitepapers

Weblogging Links

MS Bloggers

Recommended Books

Other Blogs

Recommended Links

Presentations (Upcoming)

Presentations (Recent)

Subscriptions

News


Upcoming Presentations


TechEd 2007, Orlando, June 4 to June 8, 2007


Books I co-authored



www.flickr.com
This is a Flickr badge showing public photos from Michael Rys. Make your own badge here.
eXTReMe Tracker

Post Categories

Article Categories



MSDN WebCast Demo: Typing XML

-- Typing
-- Execute every statement in the sample in order
-- Set filename in loading to correct location
-- (c) 2004, 2005 Microsoft Corp.

use master
USE msdn2005
GO

-- Load schema from file
declare @x XML
SELECT
@x = s
FROM OPENROWSET (BULK 'Insert your path here\Customer.xsd',
       
SINGLE_BLOB) AS TEMP(s)

select @x

IF EXISTS(select * from sys.xml_schema_collections where name='Customer')
 
DROP XML SCHEMA COLLECTION Customer

CREATE XML SCHEMA COLLECTION Customer AS @x
GO

-- Look at stored metadata
select * from sys.xml_schema_collections

-- VALIDATION
--
-------------

-- Show that validation fails
ALTER TABLE XMLdoc ALTER COLUMN doc XML(Customer)
go

-- find and remove invalid data
DELETE FROM XMLdoc WHERE doc.exist('/doc')=1
go

-- Try again: Success!
ALTER TABLE XMLdoc ALTER COLUMN doc XML(Customer)
go

-- Constrain to an XML document
ALTER TABLE XMLdoc ALTER COLUMN doc XML(DOCUMENT Customer)
go

-- Insert invalid data
INSERT INTO XMLdoc(doc) VALUES (N'<doc/>')
go

posted on Tuesday, April 12, 2005 12:07 PM by mrys





Powered by Dot Net Junkies, by Telligent Systems