如果你需要把一些xml的数据存储在数据库中那是可以的,而且不需要自己去分析出来插入。只要xml的结构写的对,就可以完整的放入数据库中。例如:
 

DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc ='<?xml version="1.0" encoding="utf-8" ?>
<ROOT>
 <Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
 <ElementType name="Products" content="empty" model="closed">
  <AttributeType name="ProductName" dt:type="string"/>
  <AttributeType name="UnitPrice" dt:type="fixed.14.4"/>
  <attribute type="ProductName"/><attribute type="UnitPrice"/>
 </ElementType>
 </Schema>
 <Products xmlns="x-schema:#Schema1" ProductName="Chai" UnitPrice="18"/>
 <Products xmlns="x-schema:#Schema1" ProductName="Chang" UnitPrice="19"/>
 <Products xmlns="x-schema:#Schema1" ProductName="Aniseed Syrup"
UnitPrice="10"/>
 <Products xmlns="x-schema:#Schema1" ProductName="Konbu" UnitPrice="6"/>
</ROOT>
'
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
    
'<root xmlns:x="x-schema:#Schema1"/>'
SELECT * FROM OPENXML (@idoc'/ROOT/x:Products',1)
          
WITH (ProductName  varchar(10),UnitPrice real)
EXEC sp_xml_removedocument @idoc
在2005测试环境下通过
posted on 2007-07-05 15:33  阳春  阅读(156)  评论(0)    收藏  举报