diff --git a/manual/ExternalFunctions.ipynb b/manual/ExternalFunctions.ipynb index 3f8e965583e28e1d436aad47ab43190f300b70a2..2df761098c987f7da69cd75be058056578db364c 100644 --- a/manual/ExternalFunctions.ipynb +++ b/manual/ExternalFunctions.ipynb @@ -4106,6 +4106,9 @@ " );\n", "```\n", "\n", + "Each entry (aka record) has its own id (it is the index in the global sequence, but for convenience the id is repeated as the ```recId``` field).\n", + "```pID``` is the Id of the parent of an entry, and 0 if the record is at the top-level.\n", + "\n", "### Files and Strings\n", "\n", "XML documents can either be stored in a file or in a B string." @@ -4171,6 +4174,60 @@ "''')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The following shows how can manipulate the data using various B operators:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/markdown": [ + "$\\mathit{TRUE}$\n", + "\n", + "**Solution:**\n", + "* $\\mathit{r2} = \\mathit{rec}(\\mathit{attributes}\\in\\{(\\text{\"attr1\"}\\mapsto\\text{\"value1\"}),(\\text{\"elemID\"}\\mapsto\\text{\"ID1\"})\\},\\mathit{element}\\in\\text{\"Tag1\"},\\mathit{meta}\\in\\{(\\text{\"xmlLineNumber\"}\\mapsto\\text{\"4\"})\\},\\mathit{pId}\\in 1,\\mathit{recId}\\in 2)$\n", + "* $\\mathit{eid} = \\text{\"ID1\"}$\n", + "* $\\mathit{xml} = \\{(1\\mapsto\\mathit{rec}(\\mathit{attributes}\\in\\{(\\text{\"version\"}\\mapsto\\text{\"0.1\"})\\},\\mathit{element}\\in\\text{\"Data\"},\\mathit{meta}\\in\\{(\\text{\"xmlLineNumber\"}\\mapsto\\text{\"3\"})\\},\\mathit{pId}\\in 0,\\mathit{recId}\\in 1)),(2\\mapsto\\mathit{rec}(\\mathit{attributes}\\in\\{(\\text{\"attr1\"}\\mapsto\\text{\"value1\"}),(\\text{\"elemID\"}\\mapsto\\text{\"ID1\"})\\},\\mathit{element}\\in\\text{\"Tag1\"},\\mathit{meta}\\in\\{(\\text{\"xmlLineNumber\"}\\mapsto\\text{\"4\"})\\},\\mathit{pId}\\in 1,\\mathit{recId}\\in 2))\\}$\n", + "* $\\mathit{version} = \\text{\"0.1\"}$\n", + "* $\\mathit{parentID} = 1$\n", + "* $\\mathit{r1} = \\mathit{rec}(\\mathit{attributes}\\in\\{(\\text{\"version\"}\\mapsto\\text{\"0.1\"})\\},\\mathit{element}\\in\\text{\"Data\"},\\mathit{meta}\\in\\{(\\text{\"xmlLineNumber\"}\\mapsto\\text{\"3\"})\\},\\mathit{pId}\\in 0,\\mathit{recId}\\in 1)$" + ], + "text/plain": [ + "TRUE\n", + "\n", + "Solution:\n", + "\tr2 = rec(attributes∈{(\"attr1\"↦\"value1\"),(\"elemID\"↦\"ID1\")},element∈\"Tag1\",meta∈{(\"xmlLineNumber\"↦\"4\")},pId∈1,recId∈2)\n", + "\teid = \"ID1\"\n", + "\txml = {(1↦rec(attributes∈{(\"version\"↦\"0.1\")},element∈\"Data\",meta∈{(\"xmlLineNumber\"↦\"3\")},pId∈0,recId∈1)),(2↦rec(attributes∈{(\"attr1\"↦\"value1\"),(\"elemID\"↦\"ID1\")},element∈\"Tag1\",meta∈{(\"xmlLineNumber\"↦\"4\")},pId∈1,recId∈2))}\n", + "\tversion = \"0.1\"\n", + "\tparentID = 1\n", + "\tr1 = rec(attributes∈{(\"version\"↦\"0.1\")},element∈\"Data\",meta∈{(\"xmlLineNumber\"↦\"3\")},pId∈0,recId∈1)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "xml = READ_XML_FROM_STRING('''\n", + "<?xml version=\"1.0\" encoding=\"ASCII\"?>\n", + " <Data version= \"0.1\">\n", + " <Tag1 elemID=\"ID1\" attr1=\"value1\" />\n", + " </Data>\n", + "''') &\n", + "\n", + "r1 = xml(1) & version = r1'attributes(\"version\") &\n", + "r2 = xml(2) & eid = r2'attributes(\"elemID\") & parentID = r2'pId" + ] + }, { "cell_type": "markdown", "metadata": {},