Ejemplo n.º 1
0
    def parse(xml, target=None, parseToInterchangeFormat =False):
        # Removes whitespace between tags to reduce potential parsing issues.
        pattern = re.compile('\<\?xml(.*)\?\>')
        if pattern.search(xml) is None:
            xml = '<?xml version="1.0" encoding="utf-8"?>' + xml
        dom = minidom.parseString(re.sub('>[\n\r\s\t]+<','><',xml))

        if target is None:
            target = {}

        cd = ConfigData()

        for node in dom.childNodes[0].childNodes:
            # Ignore whitespace generated text nodes
            if isinstance(node, (minidom.Comment, minidom.Text)):
                continue

            XMLConfigParser._parseNode(node, cd)

        if parseToInterchangeFormat:
            cd.writeToInterchangeDict(target)
        else:
            cd.writeToDict(target)

        return target
Ejemplo n.º 2
0
    def parse(xml, target=None, parseToInterchangeFormat =False):
        # Removes whitespace between tags to reduce potential parsing issues.
        pattern = re.compile('\<\?xml(.*)\?\>')
        if pattern.search(xml) is None:
            xml = '<?xml version="1.0" encoding="utf-8"?>' + xml
        dom = minidom.parseString(re.sub('>[\n\r\s\t]+<','><',xml))

        if target is None:
            target = {}

        cd = ConfigData()

        for node in dom.childNodes[0].childNodes:
            # Ignore whitespace generated text nodes
            if isinstance(node, (minidom.Comment, minidom.Text)):
                continue

            XMLConfigParser._parseNode(node, cd)

        if parseToInterchangeFormat:
            cd.writeToInterchangeDict(target)
        else:
            cd.writeToDict(target)

        return target
Ejemplo n.º 3
0
    def parse(data, target=None, parseToInterchangeFormat =False):
        d = json.loads(data)

        if target is None:
            target = {}

        cd = ConfigData()

        for n,v in DictUtils.iter(d):
            JSONConfigParser._parseElement(n, v, cd)

        if parseToInterchangeFormat:
            cd.writeToInterchangeDict(target)
        else:
            cd.writeToDict(target)

        return target
Ejemplo n.º 4
0
    def parse(data, target=None, parseToInterchangeFormat=False):
        d = json.loads(data)

        if target is None:
            target = {}

        cd = ConfigData()

        for n, v in DictUtils.iter(d):
            JSONConfigParser._parseElement(n, v, cd)

        if parseToInterchangeFormat:
            cd.writeToInterchangeDict(target)
        else:
            cd.writeToDict(target)

        return target