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.
  • 165,803
  • 30
  • 257
  • 277
Somdip Dey
  • 3,192
  • 5
  • 24
  • 53

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ரதீப்
  • 88,697
  • 17
  • 124
  • 160