first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

SQL Server 2005 t-SQL: Flippant Remarks about Using XPath Assertions Instead of XML Schema

For some crazy reason you may want to avoid making a CREATE XML SCHEMA COLLECTION statement but still validate your XML. Here is an example to do this with XPath assertions in XQuery:

IF (@xmlInput.exist('//HostName') = 0)
OR (@xmlInput.value('string-length((//HostName/text())[1])','int') = 0)
BEGIN
    SET @xmlOutput = '
    <Header>Failed to Receive Device Data</Header>
    <Code>999</Code>
    <Line>XML element “HostName” was not found or is empty.</Line>
    '
    GOTO RETURN_XML_MESSAGE
END

This technique can be used in the discussion by Denis Ruckebusch filed under “Complementing XSD with CHECK constraints” here:

http://blogs.msdn.com/denisruc/archive/2006/08/22/713342.aspx
mod date: 2007-12-11T20:57:09.000Z