'Read Xml Field From Image field Sql Server

I am trying to change the code below and read it from the image field

        DECLARE @xml XML
        SELECT @xml= x FROM OPENROWSET (BULK ''' + @XMLFILE + ''', SINGLE_BLOB) AS T(x)  

How Can I Convert To Xml Type?

SELECT @xml= FileField FROM FileListTable (FileField is İmage Field)


Solution 1:[1]

Try:

SELECT @xml = CAST(CAST(FileField AS VARBINARY(MAX)) AS XML)
FROM FileListTable

Whether this works or not, may depend on how the XML was converted to the IMAGE data type before being inserted into your table. This db<>fiddle exercises various ways of inserting XML into an IMAGE column and several ways (both good and bad) to try to get it out. Almost surprisingly, the cast to VARBINARY(MAX) and then to XML seems to handle the cases demonstrated.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 T N