Home Forums Programming XML Help with XML Splitter De-entitization, please. RE: Help with XML Splitter De-entitization, please.

  • Hi Jeff,

    in this case you will have to use CDATA (Character Data) elements in the construction of the XML.

    😎

    Here is the function with the necessary modification to handle any type of input.

    CREATE FUNCTION dbo.SplitStrings_XML

    (

    @List NVARCHAR(MAX),

    @Delimiter NVARCHAR(255)

    )

    RETURNS TABLE WITH SCHEMABINDING AS

    RETURN (

    SELECT Item = y.i.value('(./text())[1]', 'nvarchar(4000)')

    FROM (SELECT x = CONVERT(XML,

    '<i><![CDATA['

    + REPLACE(@List, @Delimiter, ']]></i><i><![CDATA[')

    + ']]></i>'

    ).query('.')

    ) AS a CROSS APPLY x.nodes('i') AS y(i)

    )

    ;

    Testing it

    SELECT *

    FROM dbo.SplitStrings_XML('"T-SQL",&,<XML>', N',')

    ;

    Output

    Item

    --------

    "T-SQL"

    &

    <XML>