【问题标题】:get_xml_as_object function not working with polymorphism - spyne 2.13.12 alpha0get_xml_as_object 函数不适用于多态性 - spyne 2.13.12 alpha0
【发布时间】:2020-01-13 09:28:14
【问题描述】:

在 spyne 2.13.12 alpha0 中加载多态对象时返回 spyne 错误。您能否看一下以下示例并指出应该使用哪个函数从 xml 文件加载对象?

import sys

from lxml import etree

from spyne.util import six
from spyne import ComplexModel, Unicode
from spyne.util.xml import get_object_as_xml_polymorphic, get_xml_as_object


class B(ComplexModel):
    _type_info = {
        '_b': Unicode,
    }

    def __init__(self):
        super().__init__()
        self._b = "b"


class C(B):
    _type_info = {
        '_c': Unicode,
    }

    def __init__(self):
        super().__init__()
        self._c = "c"


class A(ComplexModel):
    _type_info = {
        '_a': Unicode,
        '_b': B,
    }

    def __init__(self, b=None):
        super().__init__()
        self._a = 'a'
        self._b = b


a = A(b=C())
elt = get_object_as_xml_polymorphic(a, A, no_namespace=True)
xml_string = etree.tostring(elt, pretty_print=True)
if six.PY2:
    print(xml_string, end="")
else:
    sys.stdout.buffer.write(xml_string)

element_tree = etree.fromstring(xml_string)
new_a = get_xml_as_object(elt, A)

错误在最后一行,消息是

raise ValidationError(xsi_type)
spyne.error.ValidationError: ValidationError(Client.ValidationError: "The value 'C' could not be validated.")

感谢您的帮助

【问题讨论】:

    标签: spyne


    【解决方案1】:

    您的代码被用作testexample 作为PR #635 的一部分来解决您遇到的问题。请使用>=spyne-2.13.14 测试并反馈。

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 2014-01-21
      相关资源
      最近更新 更多