SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Parse XML Data to Table format


Parse XML Data to Table format

Author
Message
sivaj2k
sivaj2k
SSC Journeyman
SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)

Group: General Forum Members
Points: 98 Visits: 549
Hi friends,

declare @xml table (xmldata xml)
insert @xml select
N'<parseObject name="Motel">
<fields>
<field name="vehicleno" fieldType="int" fieldSize="">
<grammar>
<data><![CDATA[
div.biz-page-subheader li > span.i-phone-biz_details-wrap mapbox-icon span.biz-partno
]]></data>
<attribute>html</attribute>
</grammar>
</field>

</fields>
</parseObject>
'
i want to extract data in in table format

ParseObject Name FieldType FieldSize Grammar
Motel VehicleNo Int NULL div.biz-page-subheader li > span.i-phone-biz_details-wrap
mapbox-icon span.biz-partno[/size]


can any body help me.
Regards
Siva
Eirikur Eiriksson
Eirikur Eiriksson
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15116 Visits: 18598
Try this for size
Cool
declare @xml table (xmldata xml)
insert INTO @xml (xmldata) VALUES(
N'<parseObject name="Motel">
<fields>
<field name="vehicleno" fieldType="int" fieldSize="">
<grammar>
<data><![CDATA[
div.biz-page-subheader li > span.i-phone-biz_details-wrap mapbox-icon span.biz-partno
]]></data>
<attribute>html</attribute>
</grammar>
</field>

</fields>
</parseObject>
')
/*----------------*/
SELECT
RO.OT.value('@name','NVARCHAR(256)') AS [ParseObject]
,FIE.LD.value('@name','NVARCHAR(256)') AS [Name]
,FIE.LD.value('@fieldType','NVARCHAR(256)') AS [FieldType]
,NULLIF(FIE.LD.value('@fieldSize','INT'),0) AS [FieldSize]
,DA.TA.value('.[1]','NVARCHAR(MAX)') AS [Grammar]
FROM @xml X
OUTER APPLY X.xmldata.nodes('parseObject') AS RO(OT)
OUTER APPLY RO.OT.nodes('fields/field') AS FIE(LD)
OUTER APPLY FIE.LD.nodes('grammar/data') AS DA(TA)



Results
ParseObject  Name       FieldType  FieldSize   Grammar
------------ ---------- ---------- ----------- -------------------------------------------------------------------------------------
Motel vehicleno int NULL div.biz-page-subheader li > span.i-phone-biz_details-wrap mapbox-icon span.biz-partno

sivaj2k
sivaj2k
SSC Journeyman
SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)SSC Journeyman (98 reputation)

Group: General Forum Members
Points: 98 Visits: 549
Thank you Eirikur Eiriksson.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search