| 173 | } |
| 174 | |
| 175 | PyObject* XMLNode2dict(XMLNode node){ |
| 176 | PyObject *dct = PyDict_New(); |
| 177 | PyObject *opts = PyDict_New(); |
| 178 | if(node.hasAttribute("type")){ |
| 179 | PyObject *obj = pyStringFromString(node.getAttribute("type").c_str()); |
| 180 | PyDict_SetItemString(dct, "type", obj); |
| 181 | Py_DECREF(obj); |
| 182 | } |
| 183 | std::list<XMLNode> nodes = node.getNodes(); |
| 184 | std::list<XMLNode>::iterator it = nodes.begin(); |
| 185 | while(it!=nodes.end()){ |
| 186 | XMLNode subnode = *it; |
| 187 | if(subnode.getName()=="Option"){ |
| 188 | PyObject *obj; |
| 189 | if(subnode.hasAttribute("value")){ |
| 190 | obj = stringToPythonValue(subnode.getAttribute("value")); |
| 191 | }else{ |
| 192 | obj = stringToPythonValue(subnode.getContent()); |
| 193 | } |
| 194 | PyDict_SetItemString(opts, subnode.getAttribute("key").c_str(), obj); |
| 195 | Py_DECREF(obj); |
| 196 | }else{ |
| 197 | PyObject *obj = stringToPythonValue(subnode.getContent()); |
| 198 | PyDict_SetItemString(dct, subnode.getName().c_str(), obj); |
| 199 | Py_DECREF(obj); |
| 200 | } |
| 201 | ++it; |
| 202 | } |
| 203 | PyDict_SetItemString(dct, "options", opts); |
| 204 | Py_DECREF(opts); |
| 205 | return dct; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | } |
no test coverage detected