Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnydataNode.to_xml() fails #80

Open
kwatsen opened this issue Dec 19, 2020 · 2 comments
Open

AnydataNode.to_xml() fails #80

kwatsen opened this issue Dec 19, 2020 · 2 comments

Comments

@kwatsen
Copy link
Contributor

kwatsen commented Dec 19, 2020

@HRogge

The test_xml_config pytest in test-models.py in my xml-improved fork currently comments-out anydA. But if its removal is commented-out in the xml_safe_data() as follows:

OLD:

data2['test:contA'].pop('anydA')

NEW:

#data2['test:contA'].pop('anydA')

And run:

pytest -sxvv -k test_xml_config

Then the following output is produced:

  <snip/>
        # convert InstanceValue to an XML-encoded string
>       xml_obj = inst.to_xml()

tests/test_model.py:741: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
yangson/instance.py:708: in to_xml
    et = super().to_xml(filter, element)
yangson/instance.py:540: in to_xml
    m.to_xml(filter, child)
yangson/instance.py:540: in to_xml
    m.to_xml(filter, child)
yangson/instance.py:507: in to_xml
    m = self[cname]
yangson/instance.py:219: in __getitem__
    return self._member(key)
yangson/instance.py:580: in _member
    self._member_schema_node(name), self.value.timestamp)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <yangson.instance.ObjectMember object at 0x10777d4f0>, name = 'foo:bar'

    def _member_schema_node(self: InstanceNode, name: InstanceName) -> DataNode:
        qname = self.schema_node._iname2qname(name)
>       res = self.schema_node.get_data_child(*qname)
E       AttributeError: 'AnydataNode' object has no attribute 'get_data_child'

yangson/instance.py:609: AttributeError
=============================================== short test summary info ===============================================
FAILED tests/test_model.py::test_xml_config - AttributeError: 'AnydataNode' object has no attribute 'get_data_child'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================== 1 failed, 15 deselected in 0.67s ===========================================
@kwatsen kwatsen changed the title AnyDataNode.to_xml() fails AnydataNode.to_xml() fails Dec 19, 2020
@kwatsen kwatsen mentioned this issue Feb 11, 2021
@kwatsen
Copy link
Contributor Author

kwatsen commented Dec 7, 2024

Since the anydata and anyxml statements are opaque, by definition, how would it be possible to serialize XML?

Maybe the code could blindly walk the data tree, converting namespace prefixes to xmlns entries. Since JSON lists are self-describing, the conversion seems possible.

Of course, this assumes that all the prefixes are recognized, which may not be true. A user-configurable "prefix to xml-namespace" table could be used to assist.

Thoughts?

@llhotka
Copy link
Member

llhotka commented Dec 11, 2024

I don't think any general conversion method can work for everybody. For special use cases, I'd suggest to (fork and) extend Yangson in an ad hoc fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants