XML 反序列化器(Iserialzable)
我有一个 C# 类,它实现了 Iserialzable。
我正在使用 XMLSerializer 从该类的实例生成 XML。
我得到以下 XML:
<?xml version="1.0"?>
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SessionConfiguration>
<RemoteMachineName>HV-BENDA</RemoteMachineName>
</SessionConfiguration>
<SessionsCredentialsList>
<CredentialsItem>
<User>test0</User>
<Password>Pa$$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test1</User>
<Password>Pa$$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test2</User>
<Password>Pa$$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test3</User>
<Password>Pa$$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test4</User>
<Password>Pa$$word1</Password>
</CredentialsItem>
</SessionsCredentialsList>
<TIME_OUT />
<LOCAL_USERS_NUM>5</LOCAL_USERS_NUM>
</Configuration>
在代码的稍后某个时刻,我再次使用 XMLSerializer 来反序列化该 XML 文档。
我收到以下错误:
{"XML 文档 (1, 1) 中存在错误。"}
内部异常:
{"根级别的数据无效。第 1 行,位置 1。"}
有人知道可以做什么吗是问题所在吗?
一切顺利
I have a class in c# that implements Iserialzable.
I'm using a XMLSerializer that produces a XML from instance of that class.
I get the following XML:
<?xml version="1.0"?>
<Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SessionConfiguration>
<RemoteMachineName>HV-BENDA</RemoteMachineName>
</SessionConfiguration>
<SessionsCredentialsList>
<CredentialsItem>
<User>test0</User>
<Password>Pa$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test1</User>
<Password>Pa$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test2</User>
<Password>Pa$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test3</User>
<Password>Pa$word1</Password>
</CredentialsItem>
<CredentialsItem>
<User>test4</User>
<Password>Pa$word1</Password>
</CredentialsItem>
</SessionsCredentialsList>
<TIME_OUT />
<LOCAL_USERS_NUM>5</LOCAL_USERS_NUM>
</Configuration>
At some later point in the code I use a XMLSerializer again to deserial that XML document.
and I get the following error:
{"There is an error in XML document (1, 1)."}
Inner exception:
{"Data at the root level is invalid. Line 1, position 1."}
Do someone knows wat could be the problem?
All the best
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
奇怪的是,仅使用流不起作用。使用 StreamReader 和 StreamWriter 解决了这个问题。
谢谢
Strangely using only stream didn't work. Using StreamReader and StreamWriter solved it.
Thanks
使用美元符号可能会导致问题。尝试使用
$
代替。Usage of dollar sign might cause problems. Try using
$
instead.