0

I have a piece of sql text which uses:

Cast ('< M>' + Replace(JobNote, ',', '< /M>< M>') + '< /M>' AS XML)

and when i execute it the error generated is:

XML parsing: line 1, character 23, illegal name character can someone tell me what should I do??

(please ignore the blankspace before M> in < M>)

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Somdip Dey
  • 3,346
  • 6
  • 28
  • 60

1 Answers1

1

The space in < M> is what not allowing to cast the string as XML remove the space like

select Cast ('<M>' + Replace(JobNote, ',', '</M>') + '</M>' AS XML)

then it will work fine.

And There are few special characters are invalid in XML so it has to be replaced in JobNote with the following.

& - &amp;
< - &lt;
> - &gt;
" - &quot;
' - &#39;

select Cast ('<M>' + Replace(JobNote, ',', '</M>< M>') + '</M>' AS XML)
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172