converting text to untyped xml error

  • I have a text field that has XML in it. It is untyped and I get errors when I try to convert it from text to xml. Below is a sample of what I am trying to do

    declare @x varchar(max)

    set @x = '<a><b>abc</b>'

    select CONVERT(xml, @x)

    select CAST(@x as xml)

    and I get the following error

    Msg 9400, Level 16, State 1, Line 4

    XML parsing: line 1, character 13, unexpected end of input

    My question is, is there a way to check to see if a text field is valid XML? If not, is there a way around it easily?

    Thanks!

    Michael

  • I may be being thick but the error that you are getting states that the XML is not well formed. Put a try..catch block to eliminate the badly formed XML. The well formed XML will not generate the error.

    SQL DBA
    Every day is a school day, and don't trust anyone who tells you any different.
    http://sqlblogness.blogspot.co.uk

  • OF COURSE!!!! Sorry, I had a huge brain fart! Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply