VB/VBA 中的 XML 反序列化
我在 MS Access 数据库中有一组 VBA 类。 我有一个 xml 字符串,其中包含我想用来创建新类的数据。
除了单独设置每个属性之外,是否有一种简单的方法可以将 XML 反序列化到我的对象中?
我已经看到使用 TypeLib 库的代码
Public Sub ISerializable_Deserialize(xml As IXMLDOMNode)
Dim tTLI As TLIApplication
Dim tInvoke As InvokeKinds
Dim tName As String
Dim tMem As MemberInfo
tInvoke = VbLet
For Each tMem In TLI.ClassInfoFromObject(Me).Members
tName = LCase(tMem.Name)
CallByName Me, tMem.Name, VbLet, xml.Attributes.getNamedItem(tName).Text
Next tMem
End Sub
,但这似乎不适用于标准类模块。我收到 429 错误:
ActiveX Component Cannot Be Created
还有其他人可以帮助我吗?如果可以的话,我宁愿不必手动设置每个属性,其中一些类非常巨大!
I have a set of VBA classes in an MS Access database.
I have an xml string with data I want to create new classes with.
Other than setting each property individually, is there an easy way to deserialize the XML into my object?
I've seen the code using the TypeLib library
Public Sub ISerializable_Deserialize(xml As IXMLDOMNode)
Dim tTLI As TLIApplication
Dim tInvoke As InvokeKinds
Dim tName As String
Dim tMem As MemberInfo
tInvoke = VbLet
For Each tMem In TLI.ClassInfoFromObject(Me).Members
tName = LCase(tMem.Name)
CallByName Me, tMem.Name, VbLet, xml.Attributes.getNamedItem(tName).Text
Next tMem
End Sub
but this doesn't seem to work with the standard class modules. I get a 429 error:
ActiveX Component Cannot Be Created
Can anyone else help me out? I'd rather not have to set each propery by hand if I can help it, some of these classes are huge!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您永远不会在该代码中实例化
tTLI
。然后将其称为TLI
所以它不会工作,429错误可能是因为 TypeInfo 库未注册,您是否将其添加为引用?如果您执行了以下操作,则可以:
如果您愿意,可以将
InvokeHook
替换为CallByName
。You never instance
tTLI
in that code & and later refer to it as justTLI
so it wont work, the 429 error may be because the TypeInfo library isn't registered, did you add it as a reference?If you did the following will work:
You can replace
InvokeHook
withCallByName
if you wish.