当字符串字段值为空格时,XMLSerializer 中出现问题
使用 XMLSerializer 保存从 myClass 这样的类创建的对象
Public Class MyClass
{
Public String test = " " ;
}
将导致:
<MyClass>
<test> </test>
</MyClass>
但是当我想加载 xml 文件时,它看起来像是删除了我需要的空白。 我该如何解决这个问题? 谢谢
using XMLSerializer for saving an object created from a class like myClass
Public Class MyClass
{
Public String test = " " ;
}
will result :
<MyClass>
<test> </test>
</MyClass>
but when I want to load the xml file looks like it's removing the white space ,which I need .
How can I solve this problem ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法重现 - 看起来很好:
输出:
并且
它可能有助于更具体地说明您如何尝试查看它,这样它“看起来像是在删除空白”。
Cannot reproduce - it seems fine:
outputs:
and
It might help to be more specific about how you are trying to view it, such that it "looks like it's removing the white space".
我在读取 XML 文件时遇到了类似的问题。我还没有使用 XMLSerializer,但在将 XML 文件作为 XMLDocument 设置 XMLDocument.PreserveWhitespace = true 读取时。
I was running into a similar problem when reading my XML file. I haven't done work with XMLSerializer but when reading in an XML file as an XMLDocument set XMLDocument.PreserveWhitespace = true.