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>)

7
  • What does JobNote contain? Commented Dec 18, 2014 at 16:45
  • Varchar ....JobNote contains string i am actually trying stackoverflow.com/questions/27543755/appending-data-in-t-sql/… so i have another part in the first select which fetches: Split.a.value('.', 'VARCHAR(100)') JobNote Commented Dec 18, 2014 at 16:45
  • Alex K mean what is the content of JobNote. Some character in there is illegal Commented Dec 18, 2014 at 16:47
  • oh. such as &, <,>, etc..you mean?? what if I do need to keep those characters.....is there some way around this? Commented Dec 18, 2014 at 16:49
  • Don't cast as XML? You can't use that output externally, so... Commented Dec 18, 2014 at 16:57

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.