How can I read a xml file and load the content, similar to the json example.
json code shared is for reference which is working and I want to load xml content in a similar way. Have tried minidom parse in xml but when I tried to get the methods from readed content, it throws me error AttributeError: keys_exists() expects dict as first argument.
with open(xml_file) as f:
content = f.read()
self.spec = xml.loads(content)
json file can load the content as :
with open(json_file) as f:
content = f.read()
self.spec = json.loads(content)
Have tried minidom parse for xml :
with open(xml_file) as f:
self.spec = minidom.parse(xml_file)
Trying to get the methods but it displayed the error AttributeError: keys_exists() expects dict as first argument.
on execution:
def get_methods(self):
''' Get all the methods
Return:
All the methods (array)
'''
list_methods = []
if keys_exists(self.spec,self.name,'methods'):
for action in self.spec[self.name]['methods'].keys():
for method in self.spec[self.name]['methods'] [action].keys():
if method == 'method':
list_methods.append(self.spec[self.name]['method'] [action][method])
return list_methods
xml file format:
<class>
<grpname>test123</grpname>
<name>test123_binding</name>
<descr>test</descr>
<properties>
<property>
<name>test</name>
<type>test_binding[]</type>
<access>readonly</access>
</property>
<property>
<name>test_action_binding</name>
<type>test_action_binding[]</type>
<access>readonly</access>
</property>
</properties>
<methods>
<method>
<name>get</name>
<in-parameters>
<parameter>
<name>session</name>
<type>service</type>
<mandatory>true</mandatory>
</parameter>
</in-parameters>
<out-parameter>
<parameter>
<type>test_binding</type>
</parameter>
</out-parameter>
</method>
</methods>