4
votes

how to fix error illegal qualified name character in this sample :

 Declare @Str As nvarchar(256)
 Set @Str = N'<Log "ReceiptStockHNo="2" ReceiptStockHDate="Feb  4 2" Comment="" />'
 Select Cast(@Str As xml) 

Error :

Msg 9455, Level 16, State 1, Line 5
XML parsing: line 1, character 6, illegal qualified name character

1

1 Answers

6
votes

What is this extra " ? .

enter image description here

Remove the " and it will work.

Additional information :

To prevent future errors for needed encoded characters like & , < , use the appropriate replacement :

 Declare @Str As nvarchar(256)
 Set @Str =  '<tag>&</tag>'
 Select Cast(@Str As xml) 

Will yield :

Msg 9421, Level 16, State 1, Line 3 XML parsing: line 1, character 7
illegal name character

While changing < to &lt; :

 Declare @Str As nvarchar(256)
 Set @Str =  '<tag>&lt;</tag>'
 Select Cast(@Str As xml) 

Will be Ok.