Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to pass an embedded string using xml to a web service. I am trying to use UTF8 encoding. I am using string builder and string writer, but I am not able to pass the parameter to the inputxml as "writer" itself. so have to cast it to "writer.ToString()". then its converted to UTF16 and created forwarded slash between each elelment.
Please help. how i embed my string to xml?


NB: Using ASP.net and C#.Net, .Net fRame work 4.5

What I have tried:

protected string BuildXmlSTR(string NameofParty)
{
XmlWriterSettings setting = new XmlWriterSettings();
setting.Encoding=Encoding.UTF8;

StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
using (XmlWriter w = XmlWriter.Create(writer, setting))
{
w.WriteStartDocument(true);
w.WriteStartElement("data");

w.WriteElementString("child", "myvalue");

w.WriteEndElement();//data


}
string test = writer.ToString();
return test.ToString();
}
Posted
Updated 26-Dec-19 6:47am
v2

1 solution

I think this will point you in the right direction. It seems the default encoding, utf-16, can be overridden. c# - XmlWriter to Write to a String Instead of to a File - Stack Overflow[^]
 
Share this answer
 
Comments
AnieMVC 26-Dec-19 13:25pm    
I did subclass String Writer but it didnt work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900