Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:support repeated elements when building node dicts
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:87b48d4651730c90dd0f1ac3b7a9ebe3d7ab2e9b
User & Date: brandon 2017-12-24 22:54:38
Context
2018-01-16
21:37
fix use of lists in nested node objects check-in: 2f68ce1cc2 user: brandon tags: trunk
2017-12-24
22:54
support repeated elements when building node dicts check-in: 87b48d4651 user: brandon tags: trunk
2015-05-05
22:15
catch nonetype biblio in ifiction check-in: 4786f6c630 user: brandon tags: trunk
Changes

Changes to treatyofbabel/ifiction.py.

1
2
3
4
5
6
7
8
9
10
11
12
..
59
60
61
62
63
64
65








66
67
68
69
70
71
72
73
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106



107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
#
#       ifiction.py
#
#       Copyright © 2012, 2013, 2014, 2015 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
................................................................................
        contents) of the node.

    """
    node_dict = {}
    for child in xml_node.childNodes:
        name = child.nodeName.lower()
        if child.hasChildNodes():








            node_dict[name] = build_dict_from_node(child)
        else:
            # This protects against weird XML formatting, like multiple text
            # child nodes at the same level
            if len(xml_node.childNodes) > 1:
                continue
            value = child.nodeValue
            if value is not None:
................................................................................
    """
    node = ifiction_dom.createElement(node_name)
    for key, value in node_dict.items():
        key = key.lower()
        if value is None or value == "":
            continue
        child = None
        try:
            value.keys()
        except:
            tag = ifiction_dom.createElement(key)
            child = ifiction_dom.createTextNode(value)
        else:
            if len(value.keys()) > 0:
                tag = build_node_from_dict(ifiction_dom, key, value)
            else:
                tag = ifiction_dom.createElement(key)
                child = ifiction_dom.createTextNode('')



        node.appendChild(tag)
        if child is not None:
            tag.appendChild(child)
    return node


def is_ifiction(xml_dom_doc):




|







 







>
>
>
>
>
>
>
>
|







 







|
|
|
|
|
|





>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
#
#       ifiction.py
#
#       Copyright © 2012, 2013, 2014, 2015, 2017 Brandon Invergo <brandon@invergo.net>
#
#       This file is part of pyifbabel.
#
#       pyifbabel is free software: you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation, either version 3 of the License, or
#       (at your option) any later version.
................................................................................
        contents) of the node.

    """
    node_dict = {}
    for child in xml_node.childNodes:
        name = child.nodeName.lower()
        if child.hasChildNodes():
            if name in node_dict:
                # For repeated entries, build up a list
                if isinstance(node_dict[name], list):
                    node_dict[name].append(build_dict_from_node(child))
                else:
                    node_dict[name] = [node_dict[name],
                                       build_dict_from_node(child)]
            else:
                node_dict[name] = build_dict_from_node(child)
        else:
            # This protects against weird XML formatting, like multiple text
            # child nodes at the same level
            if len(xml_node.childNodes) > 1:
                continue
            value = child.nodeValue
            if value is not None:
................................................................................
    """
    node = ifiction_dom.createElement(node_name)
    for key, value in node_dict.items():
        key = key.lower()
        if value is None or value == "":
            continue
        child = None
        if isinstance(value, list):
            for val in value:
                tag = build_node_from_dict(ifiction_dom, key, val)
                node.appendChild(tag)
            return node
        elif isinstance(value, dict):
            if len(value.keys()) > 0:
                tag = build_node_from_dict(ifiction_dom, key, value)
            else:
                tag = ifiction_dom.createElement(key)
                child = ifiction_dom.createTextNode('')
        else:
            tag = ifiction_dom.createElement(key)
            child = ifiction_dom.createTextNode(value)
        node.appendChild(tag)
        if child is not None:
            tag.appendChild(child)
    return node


def is_ifiction(xml_dom_doc):