Closed ajays20078 closed 7 years ago
Thanks a lot for your report! I'll look into this.
How about the master head after the commit de1267b ? It looks fine as far as I tested.
In [1]: import os,sys; sys.path.insert(0, os.curdir); import anyconfig
In [2]: xml_s = open("/tmp/0.xml").read()
In [3]: from __future__ import print_function
In [4]: print(xml_s)
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="separator" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.example.separator.domain.Job</class>
<class>com.example.separator.domain.Module</class>
<class>com.example.separator.domain.Condition</class>
<class>com.example.separator.domain.ConditionValue</class>
<class>com.example.separator.domain.Coupon</class>
<class>com.example.separator.domain.CouponCondition</class>
<class>com.example.separator.domain.CouponInstance</class>
<class>com.example.separator.domain.CouponInstanceUsage</class>
<class>com.example.separator.domain.CouponSchedule</class>
<class>com.example.separator.domain.CustomCouponAttribute</class>
<class>com.example.separator.domain.CouponInstanceUser</class>
<class>com.example.separator.domain.CouponRule</class>
<class>com.example.separator.domain.CouponRuleLeftOperand</class>
<class>com.example.separator.domain.CouponRuleItem</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
In [5]: xml_d = anyconfig.loads(xml_s, ac_parser="xml")
In [6]: xml_d
Out[6]:
{'persistence': {'@attrs': {'version': '2.0',
'xmlns': 'http://java.sun.com/xml/ns/persistence',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'{http://www.w3.org/2001/XMLSchema-instance}schemaLocation': 'http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd'},
'persistence-unit': {'@attrs': {'name': 'separator',
'transaction-type': 'RESOURCE_LOCAL'},
'@children': [{'provider': 'org.hibernate.ejb.HibernatePersistence'},
{'class': 'com.example.separator.domain.Job'},
{'class': 'com.example.separator.domain.Module'},
{'class': 'com.example.separator.domain.Condition'},
{'class': 'com.example.separator.domain.ConditionValue'},
{'class': 'com.example.separator.domain.Coupon'},
{'class': 'com.example.separator.domain.CouponCondition'},
{'class': 'com.example.separator.domain.CouponInstance'},
{'class': 'com.example.separator.domain.CouponInstanceUsage'},
{'class': 'com.example.separator.domain.CouponSchedule'},
{'class': 'com.example.separator.domain.CustomCouponAttribute'},
{'class': 'com.example.separator.domain.CouponInstanceUser'},
{'class': 'com.example.separator.domain.CouponRule'},
{'class': 'com.example.separator.domain.CouponRuleLeftOperand'},
{'class': 'com.example.separator.domain.CouponRuleItem'},
{'exclude-unlisted-classes': 'true'}]}}}
In [7]:
I forgot about the attributes, I'll fix that also.
'{http://www.w3.org/2001/XMLSchema-instance}schemaLocation': 'http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd'},
Fixed attribute cases in the commit 9e45085.
...
In [5]: xml_d = anyconfig.loads(xml_s, ac_parser="xml")
In [6]: xml_d
Out[6]:
{'persistence': {'@attrs': {'version': '2.0',
'xmlns': 'http://java.sun.com/xml/ns/persistence',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xsi:schemaLocation': 'http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd'},
'persistence-unit': {'@attrs': {'name': 'separator',
'transaction-type': 'RESOURCE_LOCAL'},
'@children': [{'provider': 'org.hibernate.ejb.HibernatePersistence'},
{'class': 'com.example.separator.domain.Job'},
{'class': 'com.example.separator.domain.Module'},
{'class': 'com.example.separator.domain.Condition'},
{'class': 'com.example.separator.domain.ConditionValue'},
{'class': 'com.example.separator.domain.Coupon'},
{'class': 'com.example.separator.domain.CouponCondition'},
{'class': 'com.example.separator.domain.CouponInstance'},
{'class': 'com.example.separator.domain.CouponInstanceUsage'},
{'class': 'com.example.separator.domain.CouponSchedule'},
{'class': 'com.example.separator.domain.CustomCouponAttribute'},
{'class': 'com.example.separator.domain.CouponInstanceUser'},
{'class': 'com.example.separator.domain.CouponRule'},
{'class': 'com.example.separator.domain.CouponRuleLeftOperand'},
{'class': 'com.example.separator.domain.CouponRuleItem'},
{'exclude-unlisted-classes': 'true'}]}}}
In [7]:
Will check and revert.
Yeah, this works. Thanks for the quick fix.
Example of xml:
anyconfig.load is resulting in a dictionary with weird keys.
and when you check the keys of the dict, it shows them as
dict_keys(['persistence', '{http://java.sun.com/xml/ns/persistence}persistence'])
Whereas when you load the same using xmltodict, it handles it properly.