I have following simple xsd schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MyUrl" type="xsd:anyURI"/>
</xsd:schema>'
I have SQL Server 2008 R2 and I want to validate my variable against this schema. It works, but variable x got validated even if it's empty or whitespace, however empty xml isn't valid against this schema.
Why I got these results?
TSQL code:
CREATE XML SCHEMA COLLECTION dbo.xsdTest AS
N'<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MyUrl" type="xsd:anyURI"/>
</xsd:schema>'
GO
DECLARE @x XML(dbo.xsdTest)
SET @x = ' ' --no error
By default the XML data type accepts XML fragments as valid XML.
The XML data can contain multiple zero or more elements at the top level.
You can specify that the XML must be a valid XML document like this.
declare @x xml(document dbo.xsdTest)
set @x = '' -- error here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With