"
+ ]
+ },
+ "execution_count": null,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "hl_md('a child')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "20467373",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/markdown": [
+ "---\n",
+ "\n",
+ "### to_xml\n",
+ "\n",
+ "> to_xml (node:tuple, hl=False)\n",
+ "\n",
+ "*Convert `node` to an XML string.*\n",
+ "\n",
+ "| | **Type** | **Default** | **Details** |\n",
+ "| -- | -------- | ----------- | ----------- |\n",
+ "| node | tuple | | XML structure in `xt` format |\n",
+ "| hl | bool | False | Syntax highlight response? |"
+ ],
+ "text/plain": [
+ "---\n",
+ "\n",
+ "### to_xml\n",
+ "\n",
+ "> to_xml (node:tuple, hl=False)\n",
+ "\n",
+ "*Convert `node` to an XML string.*\n",
+ "\n",
+ "| | **Type** | **Default** | **Details** |\n",
+ "| -- | -------- | ----------- | ----------- |\n",
+ "| node | tuple | | XML structure in `xt` format |\n",
+ "| hl | bool | False | Syntax highlight response? |"
+ ]
+ },
+ "execution_count": null,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "show_doc(to_xml)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "7a7fe4c6",
+ "metadata": {},
+ "source": [
+ "Now we can convert that HTML data structure we created into XML:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "80a0cde7",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/markdown": [
+ "```xml\n",
+ "\n",
+ " This is a paragraph
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
This is a header
\n",
+ " This is a sub-header
\n",
+ " \n",
+ "\n",
+ "```"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": null,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "to_xml(a, hl=True)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2795f9fc",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/markdown": [
+ "---\n",
+ "\n",
+ "### json_to_xml\n",
+ "\n",
+ "> json_to_xml (d:dict, rnm:str)\n",
+ "\n",
+ "*Convert `d` to XML.*\n",
+ "\n",
+ "| | **Type** | **Details** |\n",
+ "| -- | -------- | ----------- |\n",
+ "| d | dict | JSON dictionary to convert |\n",
+ "| rnm | str | Root name |\n",
+ "| **Returns** | **str** | |"
+ ],
+ "text/plain": [
+ "---\n",
+ "\n",
+ "### json_to_xml\n",
+ "\n",
+ "> json_to_xml (d:dict, rnm:str)\n",
+ "\n",
+ "*Convert `d` to XML.*\n",
+ "\n",
+ "| | **Type** | **Details** |\n",
+ "| -- | -------- | ----------- |\n",
+ "| d | dict | JSON dictionary to convert |\n",
+ "| rnm | str | Root name |\n",
+ "| **Returns** | **str** | |"
+ ]
+ },
+ "execution_count": null,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "## How to use"
+ "show_doc(json_to_xml)"
]
},
{
"cell_type": "markdown",
+ "id": "140a35a2",
"metadata": {},
"source": [
- "Fill me in please! Don't forget code examples:"
+ "JSON doesn't map as nicely to XML as the data structure used in the previous section, but for simple XML trees it can be convenient -- for example:"
]
},
{
"cell_type": "code",
"execution_count": null,
+ "id": "005a5be4",
"metadata": {},
"outputs": [
{
"data": {
+ "text/markdown": [
+ "```xml\n",
+ "\n",
+ " Howard\n",
+ " \n",
+ " - Jeremy
\n",
+ " - Peter
\n",
+ " \n",
+ " \n",
+ " Queensland\n",
+ " Australia\n",
+ " \n",
+ "\n",
+ "```"
+ ],
"text/plain": [
- "2"
+ ""
]
},
"execution_count": null,
@@ -73,12 +2040,15 @@
}
],
"source": [
- "1+1"
+ "a = dict(surname='Howard', firstnames=['Jeremy','Peter'],\n",
+ " address=dict(state='Queensland',country='Australia'))\n",
+ "hl_md(json_to_xml(a, 'person'))"
]
},
{
"cell_type": "code",
"execution_count": null,
+ "id": "207f9715",
"metadata": {},
"outputs": [],
"source": []
@@ -86,11 +2056,11 @@
],
"metadata": {
"kernelspec": {
- "display_name": "python3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
}
},
"nbformat": 4,
- "nbformat_minor": 4
+ "nbformat_minor": 5
}