不必要的?当我尝试动态创建xml时 [英] Unnecessary ? comes when i try to create xml dynamically
本文介绍了不必要的?当我尝试动态创建xml时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码。这里的问题是在执行不必要的''?''符号时。
I am using the code below. The problem here is while executing an unnecessary ''?'' sign comes.
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();
推荐答案
你的XML文件包含一些超出ASCII的Unicode字符,控制台当时不会显示,替换它们通常是''?''。你需要让控制台显示Unicode:
这样做:
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:
System.Console.OutputEncoding = System.Text.Encoding.Unicode;
这令人困惑。 System.Text.Encoding.Unicode
并不真正意味着Unicode,但是,在那个奇怪的Microsoft行话中,它意味着Unicode的UTF-16LE编码。 Unicode本身不是编码。请参阅:
http://www.Unicode.org [ ^ ],
http://www.unicode.org/faq/utf_bom.html [ ^ ]。
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[^].
我没有确切的理由'''''。我只是通过删除第零位置的元素来解决这个问题。我认为其原因与Sergey Alexandrovich所述相同。
xmlOutput = xmlOutput.Remove(0,1);
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);
这篇关于不必要的?当我尝试动态创建xml时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文