你可以使用这样的东西:
DECLARE @XML XML
SET @XML = '<?xml version="1.0" encoding="utf-8"?>
<member xmlns="http://testxsd" xmlns:xsi="http:...XMLSchema-instance">
<Person>
<Name>Jorge</Name>
<LastName>Bond</LastName>
</Person>
<Person>
<Name>Jorge</Name>
<LastName>Bond</LastName>
</Person>
</member>'
;WITH XMLNAMESPACES(DEFAULT 'http://testxsd')
SELECT
PersonName = XPerson.value('(Name)[1]', 'varchar(50)'),
PersonLastName = XPerson.value('(LastName)[1]', 'varchar(50)')
FROM @XML.nodes('/member/Person') AS XTbl(XPerson)
这将为您提供以下输出:
当然,如果您想将该数据插入到表中,您可以使用:
;WITH XMLNAMESPACES(DEFAULT 'http://testxsd')
INSERT INTO dbo.Person(Name, LastName)
SELECT
PersonName = XPerson.value('(Name)[1]', 'varchar(50)'),
PersonLastName = XPerson.value('(LastName)[1]', 'varchar(50)')
FROM @XML.nodes('/member/Person') AS XTbl(XPerson)