MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
Storing/retrieving XML -

in Search

Storing/retrieving XML

Last post 06-20-2008 6:30 AM by Thani. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-16-2008 9:26 AM

    • pws
    • Top 50 Contributor
    • Joined on 06-10-2008
    • Posts 5

    Storing/retrieving XML

    hello,

     I want to insert records into my db with a column of type XML.  I have XML files on my filesystem that I want to copy in - what is the best method to do this?

     

    thnx!

     

  • 06-19-2008 12:06 PM In reply to

    • pws
    • Top 50 Contributor
    • Joined on 06-10-2008
    • Posts 5

    Re: Storing/retrieving XML

    Figured it out!  Just a matter of using bulk inserts as blobs ... nice!

  • 06-20-2008 6:30 AM In reply to

    • Thani
    • Top 500 Contributor
    • Joined on 06-20-2008
    • Posts 1

    Re: Storing/retrieving XML

    Hi,

               You need to store xml value to the xmlcolumn.

    For example:

     ---------------------------------------------------

    -- Table with XML Column

    create table xml_tab(a int not null identity(1,1),b xml)

    -- Inserting Value to XML Column

    insert into xml_tab(b) values('<?xml version="1.0"?>

    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"

    xmlns:o="urn:schemas-microsoft-com:office:office"

    xmlns:x="urn:schemas-microsoft-com:office:excel"

    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"

    xmlns:html="http://www.w3.org/TR/REC-html40">

    <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">

    <LastAuthor>tselvam</LastAuthor>

    <Created>1996-10-14T23:33:28Z</Created>

    <LastSaved>2008-06-20T13:32:13Z</LastSaved>

    <Version>10.2625</Version>

    </DocumentProperties>

    <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">

    <DownloadComponents/>

    <LocationOfComponents HRef="file:///E:\"/>

    </OfficeDocumentSettings>

    <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">

    <WindowHeight>9300</WindowHeight>

    <WindowWidth>15135</WindowWidth>

    <WindowTopX>120</WindowTopX>

    <WindowTopY>120</WindowTopY>

    <AcceptLabelsInFormulas/>

    <ProtectStructure>False</ProtectStructure>

    <ProtectWindows>False</ProtectWindows>

    </ExcelWorkbook>

    <Styles>

    <Style ss:ID="Default" ss:Name="Normal">

    <Alignment ss:Vertical="Bottom"/>

    <Borders/>

    <Font/>

    <Interior/>

    <NumberFormat/>

    <Protection/>

    </Style>

    </Styles>

    <Worksheet ss:Name="Sheet1">

    <Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="3" x:FullColumns="1"

    x:FullRows="1">

    <Row>

    <Cell><Data ss:Type="String">empno</Data></Cell>

    <Cell><Data ss:Type="String">ename</Data></Cell>

    <Cell><Data ss:Type="String">sal</Data></Cell>

    <Cell><Data ss:Type="String">deptno</Data></Cell>

    </Row>

    <Row>

    <Cell><Data ss:Type="Number">1</Data></Cell>

    <Cell><Data ss:Type="String">ram</Data></Cell>

    <Cell><Data ss:Type="Number">1000</Data></Cell>

    <Cell><Data ss:Type="Number">10</Data></Cell>

    </Row>

    <Row>

    <Cell><Data ss:Type="Number">2</Data></Cell>

    <Cell><Data ss:Type="String">kumar</Data></Cell>

    <Cell><Data ss:Type="Number">2000</Data></Cell>

    <Cell><Data ss:Type="Number">20</Data></Cell>

    </Row>

    </Table>

    <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">

    <Selected/>

    <Panes>

    <Pane>

    <Number>3</Number>

    <ActiveRow>6</ActiveRow>

    <ActiveCol>3</ActiveCol>

    </Pane>

    </Panes>

    <ProtectObjects>False</ProtectObjects>

    <ProtectScenarios>False</ProtectScenarios>

    </WorksheetOptions>

    </Worksheet>

    <Worksheet ss:Name="Sheet2">

    <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">

    <ProtectObjects>False</ProtectObjects>

    <ProtectScenarios>False</ProtectScenarios>

    </WorksheetOptions>

    </Worksheet>

    <Worksheet ss:Name="Sheet3">

    <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">

    <ProtectObjects>False</ProtectObjects>

    <ProtectScenarios>False</ProtectScenarios>

    </WorksheetOptions>

    </Worksheet>

    </Workbook>

    ')

    -- Seleting XML Column Value

    select a,b from XML_tab

    Thanks,

    Thani.

Page 1 of 1 (3 items)