4

I am generating XML as follows:

SET @xml = (
        SELECT 
                PersonalMessage AS [Personal_Message]
        FROM #TemporaryDB
        FOR XML PATH ('Order'), ROOT ('Orders'), ELEMENTS
        );

Next I add encoding info:

SELECT N'<?xml version="1.0" encoding="utf-8"?>' + Convert(nvarchar(max), @XML) 

And when I save my XML with bcp I get something like this:

<?xml version="1.0" encoding="utf-8"?>
<Orders><Order>
<Personal_Message>Liebe X1 und X2,
"Wir wuenschten wir koennten heute mit euch zusammen sitzen. Das holen wir bald wieder nach."
Eure &amp; Ina </Personal_Message></Order></Orders>

But I want something like this:

<?xml version="1.0" encoding="utf-8"?>
<Orders><Order>
<Personal_Message>Liebe X1 und X2,&#13;&#13; &quot;Wir wuenschten wir koennten heute mit euch zusammen sitzen. Das holen wir bald wieder nach.&quot; &#13;&#13;Eure &amp; Ina </Personal_Message></Order></Orders>

So I want to change C/R to &#13; and for example " to &quot;.

Please, advise me. How can I do this?

4
  • can you include your bcp command here? what is the format in your bcp? Commented Apr 29, 2015 at 13:01
  • bcp TABLENAME out path/fle.xml -S server -T -c Commented Apr 29, 2015 at 13:06
  • do you insert this xml back into a table and then use a bcp on that table? Commented Apr 29, 2015 at 13:14
  • Yes, exactly. And still I have this problem. Commented Apr 29, 2015 at 21:20

1 Answer 1

1

You might have to replace it

SET @xml = (
        SELECT 
                Replace(Replace(Replace(PersonalMessage,char(13),'&#13;'),char(10),''),'"','&quot;') AS [Personal_Message]
        FROM #TemporaryDB
        FOR XML PATH ('Order'), ROOT ('Orders'), ELEMENTS
        );
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.