asp.netsqlxml

store XML file data into a SQL XML datatype field


Do I store this XML file data into a SQL XML datatype field?

How do I write to it without writing into a XML file?


Solution

  • Its not clear to me what you want. But you can store the xml file into a xml field and manipulate this field whatever you want.

    Oracle database allows you to create a table based on a xml file, and changes on the table reflect over the xml file, you cant do that in SQL Server.

    Anyway, you can manipulate a xml field like this:

    declare @friends xml
    
    set @friends =
    '
    <friends>
        <friend>
            <id>3</id>
        </friend>
        <friend>
            <id>6</id>
        </friend>
        <friend>
            <id>15</id>
        </friend>
    </friends>
    '
    
    select
        template.item.value('.', 'bigint') as id
    from @friends.nodes('//friends/friend/id') template(item)