Doc1
and its sub elements are in the namespace http://www.sample.com/file
. Use WITH XMLNAMESPACES
to align the query with this namespace:
DECLARE @XML XML;
SET @XML=N'
<Doc1 xmlns="http://www.sample.com/file"
xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance"
xsi:schemaLocation="http://www.sample.com/file/long/path.xsd">
<header>
<stuff>data</stuff>
<morestuff>data</morestuff>
</header>
</Doc1>';
WITH XMLNAMESPACES('http://www.sample.com/file' as x)
SELECT
T.c.query('x:stuff').value('.', 'char(50)') AS stuff1,
T.c.query('x:morestuff').value('.', 'VARCHAR(20)') AS morestuff
FROM @XML.nodes('x:Doc1/x:header') AS T(c);