|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "vscode": { |
| 7 | + "languageId": "plaintext" |
| 8 | + } |
| 9 | + }, |
| 10 | + "source": [ |
| 11 | + "# dict to xml\n" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": 14, |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [ |
| 19 | + { |
| 20 | + "name": "stdout", |
| 21 | + "output_type": "stream", |
| 22 | + "text": [ |
| 23 | + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", |
| 24 | + "<project><actions></actions><description></description><keepDependencies>false</keepDependencies><properties><com.sonyericsson.rebuild.RebuildSettings plugin=\"rebuild@332.va_1ee476d8f6d\"><autoRebuild>false</autoRebuild><rebuildDisabled>true</rebuildDisabled></com.sonyericsson.rebuild.RebuildSettings></properties></project>\n" |
| 25 | + ] |
| 26 | + } |
| 27 | + ], |
| 28 | + "source": [ |
| 29 | + "import xmltodict\n", |
| 30 | + "\n", |
| 31 | + "d = js = {\n", |
| 32 | + " \"project\": {\n", |
| 33 | + " \"actions\": None,\n", |
| 34 | + " \"description\": None,\n", |
| 35 | + " \"keepDependencies\": \"false\",\n", |
| 36 | + " \"properties\": {\n", |
| 37 | + " \"com.sonyericsson.rebuild.RebuildSettings\": {\n", |
| 38 | + " \"@plugin\": \"rebuild@332.va_1ee476d8f6d\",\n", |
| 39 | + " \"autoRebuild\": \"false\",\n", |
| 40 | + " \"rebuildDisabled\": \"true\",\n", |
| 41 | + " }\n", |
| 42 | + " },\n", |
| 43 | + " \n", |
| 44 | + " }\n", |
| 45 | + "}\n", |
| 46 | + "x = xmltodict.unparse(d)\n", |
| 47 | + "print(x)" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "markdown", |
| 52 | + "metadata": { |
| 53 | + "vscode": { |
| 54 | + "languageId": "plaintext" |
| 55 | + } |
| 56 | + }, |
| 57 | + "source": [ |
| 58 | + "# xml to dict\n" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "code", |
| 63 | + "execution_count": 13, |
| 64 | + "metadata": {}, |
| 65 | + "outputs": [ |
| 66 | + { |
| 67 | + "name": "stdout", |
| 68 | + "output_type": "stream", |
| 69 | + "text": [ |
| 70 | + "{'project': {'actions': None, 'description': None, 'keepDependencies': 'false'}}\n" |
| 71 | + ] |
| 72 | + } |
| 73 | + ], |
| 74 | + "source": [ |
| 75 | + "with open(\"file/test.xml\") as f:\n", |
| 76 | + " rest = xmltodict.parse(f.buffer)\n", |
| 77 | + " print(rest)" |
| 78 | + ] |
| 79 | + } |
| 80 | + ], |
| 81 | + "metadata": { |
| 82 | + "kernelspec": { |
| 83 | + "display_name": ".venv", |
| 84 | + "language": "python", |
| 85 | + "name": "python3" |
| 86 | + }, |
| 87 | + "language_info": { |
| 88 | + "codemirror_mode": { |
| 89 | + "name": "ipython", |
| 90 | + "version": 3 |
| 91 | + }, |
| 92 | + "file_extension": ".py", |
| 93 | + "mimetype": "text/x-python", |
| 94 | + "name": "python", |
| 95 | + "nbconvert_exporter": "python", |
| 96 | + "pygments_lexer": "ipython3", |
| 97 | + "version": "3.12.5" |
| 98 | + } |
| 99 | + }, |
| 100 | + "nbformat": 4, |
| 101 | + "nbformat_minor": 2 |
| 102 | +} |
0 commit comments