pyangbind icon indicating copy to clipboard operation
pyangbind copied to clipboard

XML Deserialisation

Open Marshall700 opened this issue 4 years ago • 1 comments
trafficstars

I am trying to deserialise XML into a python object using pybindITEFXMLDecode.

with manager.connect(host=host, port=22,username=user, hostkey_verify=False,password=passw,device_params={'name':'iosxr'}) as m:
   test = m.get(filter=('subtree','<interfaces xmlns="http://openconfig.net/yang/interfaces"><interface><name>TenGigE0/3/0/0</name></interface></interfaces>'))

oi = pybindIETFXMLDecoder.load_xml(objectify.fromstring(str(con)), oc_interfaces, "openconfig_interfaces")

but am going the following error.

Traceback (most recent call last): File "netconf-xml-to-pyang.py", line 18, in <module> oi = pybindIETFXMLDecoder.load_xml(objectify.fromstring(str(con)), oc_interfaces, "openconfig_interfaces") File "/home/user-new/netconfTest/lib64/python3.6/site-packages/pyangbind/lib/serialise.py", line 491, in load_xml raise AttributeError("Invalid attribute specified (%s)" % ykey) AttributeError: Invalid attribute specified (interface)

anyone any ideas? I am essentially just trying to consume a single openconfig-interface from an ios-xr device. I have created the bindings from a get_schema of the model from device. Just doesnt seem to like the input.

Marshall700 avatar Sep 18 '21 07:09 Marshall700

Taken from some code that appears to work for me...

xml_parser = objectify.makeparser(remove_comments=True, remove_blank_text=True)

...

def loadxml(data, root, xpathhelper):
    doc = objectify.fromstring(data, parser=xml_parser)
    pybindIETFXMLDecoder.load_xml(doc,
                                  None,
                                  None,
                                  obj=root,
                                  path_helper=xpathhelper)

root in my code is a thing of my own making, but for this purpose it's functionally equivalent to a FakeRoot I believe. It has been some time though so I am rusty on the details.

chrisy avatar Sep 18 '21 13:09 chrisy

Hi,

Could you please try again with recent versions of pyangbind?

Thanks.

JoseIgnacioTamayo avatar Oct 13 '23 07:10 JoseIgnacioTamayo

Closing issue without recent updates.

JoseIgnacioTamayo avatar Feb 22 '24 07:02 JoseIgnacioTamayo