没有托管代码的xml序列化?

发布于 2024-11-27 12:56:18 字数 549 浏览 6 评论 0原文

是否可以在没有托管代码(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隔纱相望 2024-12-04 12:56:18

是和不是。

是的,可以在没有托管代码的情况下进行 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).

已下线请稍等 2024-12-04 12:56:18

也许 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文