是否存在可二进制序列化的 XML 特定对象(如 XElement)?
我有一个用例,我通过 MSMQ 在线序列化对象(主要是字符串)。当我从队列中读取对象时,我希望能够判断用户想要的对象是 XML 还是字符串。我想这样做的一个好方法就是检查类型。如果它是 XmlElement,则它会变成 XML 数据,否则它会变成字符串或 CDATA。我不想只检查数据是否是有效的 XML 的原因是,有时会提供本应序列化为字符串的数据,但实际上是有效的 XML。我希望调用者能够控制反序列化为字符串或 XML。
.NET Framework 中是否有任何类型标记为可序列化,例如 XElement 或 XmlElement(两者均未标记为可序列化)?
I have a use case where I am serializing objects over the wire via MSMQ (mostly strings). When I read the object off the queue I want to be able to tell if the user meant for the object to be a XML or a string. I was thinking a good way to do this would just be to check the type. If it's XmlElement than it becomes XML data otherwise it becomes string or CDATA. The reason I don't want to just check to see if the data is valid XML is that sometimes data will be provided that is supposed to be serialized as a string but is in fact valid XML. I want the caller to be able to control the de-serialization into string or XML.
Are there any types that are marked as serializable in the .NET Framework like XElement or XmlElement (both which are not marked serializable)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不向序列化对象的类添加一个属性来告诉您它是什么?我建议使用 IsXml。
Why don't you just add a property to the class of the serialized object that tells you what it is? I'd propose IsXml.