sanand0 / xmljson

xmlsjon converts XML into Python dictionary structures (trees, like in JSON) and vice-versa.
MIT License
121 stars 33 forks source link

int in _fromstring method removing leading zero #48

Closed FeehGb closed 2 years ago

FeehGb commented 2 years ago

If value starts with 000045535 will render 45535 should use json.loads(value) insted try int and float here

import json
@staticmethod
def _fromstring(value):
    '''Convert XML string value to None, boolean, int or float'''
    # NOTE: Is this even possible ?
    if value is None:
        return None

    # FIXME: In XML, booleans are either 0/false or 1/true (lower-case !)
    if value.lower() == 'true':
        return True
    elif value.lower() == 'false':
        return False

    # FIXME: Using int() or float() is eating whitespaces unintendedly here
    try:
        return json.loads(value)
    except ValueError:
        return value