sql - xml data display as NULL in database table. why? -
i saving xml data database table using below stored procedure in table values disply null.
what prblem please me.
alter procedure [dbo].[prc_readxmldata2] ( @xmldata xml ) begin declare @hdoc int exec sp_xml_preparedocument @hdoc output,@xmldata insert xmltable (name, value) select xml.name, xml.value openxml(@hdoc,'/upgradelog/properties/property',1) with(name varchar(50) 'text()', value varchar(50) 'text()')xml exec sp_xml_removedocument @hdoc
below xml file.
<?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type='text/xsl' href='_upgradereport_files/upgradereport.xslt'?><upgradelog> <properties> <property name="solution" value="ecs_myecsinc"> </property> <property name="solution file" value="d:\working projects\ecsinc\ecsinc\ecsinc\ecs_myecsinc.sln"> </property> <property name="date" value="wednesday, july 27, 2011"> </property> <property name="time" value="20:56 pm"> </property> </properties> <event errorlevel="0" project="" source="ecs_myecsinc.sln" description="file backed d:\working projects\ecsinc\ecsinc\ecsinc\backup\ecs_myecsinc.sln"> </event> <event errorlevel="0" project="" source="ecs_myecsinc.sln" description="solution converted successfully"> </event> <event errorlevel="3" project="" source="ecs_myecsinc.sln" description="converted"> </event> </upgradelog>
select xml.name, xml.value openxml(@hdoc,'/upgradelog/properties/property',1) with( name varchar(50) '@name', value varchar(50) '@value' )
or can select right @xmldata
using sqlxml:
select t.c.value('@name', 'nvarchar(50)') name, t.c.value('@value', 'nvarchar(50)') value @xmldata.nodes('/upgradelog/properties/property') t(c)
sql fiddle demo both solutions.
Comments
Post a Comment