Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using the code below. The problem here is while executing an unnecessary '?' sign comes.
C#
XmlWriterSettings wSettings = new XmlWriterSettings();
wSettings.Indent = true;
MemoryStream ms = new MemoryStream();
XmlWriter xw = XmlWriter.Create(ms, wSettings);// Write Declaration
xw.WriteStartDocument();

// Write the root node
xw.WriteStartElement("Request");
xw.WriteStartAttribute("RequestID");
xw.WriteString("7");
xw.WriteStartAttribute("AuthenticationKey");
xw.WriteString("asdf;lkj");
// Write the books and the book elements
xw.WriteStartElement("diagnosisData");
xw.WriteStartAttribute("IDCL_Code");
xw.WriteString("101");
xw.WriteEndAttribute();

xw.WriteEndElement();

// Close the document
xw.WriteEndDocument();

// Flush the write
xw.Flush();

Byte[] buffer = new Byte[ms.Length];
buffer = ms.ToArray();
string xmlOutput = System.Text.Encoding.UTF8.GetString(buffer);
Console.WriteLine(xmlOutput);
Console.ReadKey();
Posted
Updated 13-May-13 18:44pm
v3
Comments
Sergey Alexandrovich Kryukov 14-May-13 0:33am    
Not clear at all. Your code sample does not show any '?'. Where are they?..
—SA

It your XML file contains some Unicode characters beyond ASCII, the console won't show then, replacing them by '?', as usually. You need to make console showing Unicode:

Do this:
C#
System.Console.OutputEncoding = System.Text.Encoding.Unicode;

This is confusing. System.Text.Encoding.Unicode does not really mean Unicode, but, in that weird Microsoft jargon, it means UTF-16LE encoding of Unicode. Unicode itself is not encoding. Please see:
http://www.Unicode.org[^],
http://www.unicode.org/faq/utf_bom.html[^].

—SA
 
Share this answer
 
I didn't got the exact reason for that '?'. I just got out of that by removing the element at zeroth position. I think the reason for that is same as stated by Sergey Alexandrovich.

xmlOutput = xmlOutput.Remove(0, 1);
 
Share this answer
 

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