没有托管代码的xml序列化?
是否可以在没有托管代码(cli)的情况下使用 xmlwriter(xmlserialization)?
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::Xml::Serialization;
我的 XML 序列化托管代码:
void TXML_Interface::LoadXML( String^ filename )
{
XmlSerializer^ serializer = gcnew XmlSerializer( TTEST::typeid );
FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
XmlReader^ reader = gcnew XmlTextReader( fs );
m_test = dynamic_cast<TTEST^>(serializer->Deserialize( reader ));
}
Is there a possibility to use xmlwriter (xmlserialization) without managed code (cli)?
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::Xml::Serialization;
My XML serialization managed code:
void TXML_Interface::LoadXML( String^ filename )
{
XmlSerializer^ serializer = gcnew XmlSerializer( TTEST::typeid );
FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
XmlReader^ reader = gcnew XmlTextReader( fs );
m_test = dynamic_cast<TTEST^>(serializer->Deserialize( reader ));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是和不是。
是的,可以在没有托管代码的情况下进行 XML 操作(包括序列化) - 我通常会使用 MSXML 然而,有多种方法可以在 C++ 中执行 xml 序列化(我不是一个真正的 C++ 人员,但 Google 几乎肯定是第一个查看的地方)。
然而,这使用了与 System.Xml.Serialization 命名空间中包含的机制不同的机制。不幸的是,.Net 中的 Xml 序列化都是在托管代码中实现的,因此如果您想使用它,您将需要调用托管代码(例如,通过使用
/clr
编译器选项或 COM互操作)。Yes and no.
Yes it is possible to do XML maniuplation (including serialisation) without managed code - I'd normally do this using MSXML however there are various ways to perform xml serialisation in C++ (I'm not really a C++ person but Google is almost certainly the first place to look).
However this is using a different mechanism from the ones contained in the
System.Xml.Serialization
namespace. Unfortunately for you the Xml serialisation in .Net is all implemented in managed code, and so if you want to use it you will need to call into managed code (e.g. by using the/clr
compiler option or COM interop).也许 boost::serialization 库是什么你正在寻找。
C++ 中的序列化功能相当有限,因此 boost::serialization< /a> 更像是一个框架,使您能够使自己的类可序列化。
Maybe the boost::serialization libary is what you are looking for.
Serialization capabilities are rather limited in C++ so boost::serialization is more like a framework that enable you to make your own classes serializable.