测试环境SQL2005,windows2003
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)DECLARE @idoc int;
DECLARE @doc xml;
SELECT @doc=bulkcolumn FROM OPENROWSET(
BULK 'D: test.xml',
SINGLE_BLOB) AS x
EXEC sp_xml_preparedocument @Idoc OUTPUT, @doc
SELECT * into #temp FROM OPENXML (@Idoc, '/Root/Item',2)
WITH (
[ID] varchar(10)
,[Name]varchar(10)
,[Caption]varchar(10)
)
select * from #temp
drop table #temp
/**//*--文件D: est.xml的文本内容
?xml version="1.0" encoding="UTF-8"?
Root
Item
ID1/ID
Namejinjazz/Name
Caption剪刀/Caption
/Item
Item
ID2/ID
Namezswang/Name
Caption伴水/Caption
/Item
/Root
*/
/**//*---查询结果
ID Name Caption
---------- ---------- ----------
1 jinjazz 剪刀
2 zswang 伴水
*/