Validate XML using XSD specified at runtime in SQL Server 2008?

sup191

New Member
SQL Server 2008 allows us to validate XML against an existing XML Schema Collection by defining a typed XML column/variable: \[code\]DECLARE @TypedXml XML(MyXmlSchemaCollection)\[/code\]However, as far as I can see, the XML Schema Collection has to be known at the time we define the column/variable.Is there a way to validate XML using an XML schema specified at runtime?For example:\[code\]DECLARE @Xml XMLSET @Xml = N'<person> <firstname>Ming</firstname> <lastname>The Merciless</lastname></person>'DECLARE @Xsd XMLSET @Xsd =N'<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:element name="dateofbirth" type="xs:date"/> </xs:sequence> </xs:complexType> </xs:element></xs:schema>'DECLARE @Valid BITSET @Valid = (SELECT dbo.f_ValidateXmlAgainstXsd(@Xml, @Xsd)) -- With a user-defined function?EXEC @Valid = s_ValidateXmlAgainstXsd @Xml, @Xsd -- With a stored procedure?\[/code\]
 
Back
Top