add a child element to an XML element - Maple Help

Home : Support : Online Help : Connectivity : Web Features : XMLTools : XMLTools/AddChild

XMLTools[AddChild] - add a child element to an XML element

 Calling Sequence AddChild(xmlTree, child, n)

Parameters

 xmlTree - Maple XML tree; XML element child - string or XML element; child element to add to the xmlTree n - positive integer; position where the child element is added

Description

 • The AddChild(xmlTree, child, n) command creates a new XML element from xmlTree by inserting the XML element child at the position indicated by n. Parameter n must be less than or equal to the number of children in the original tree xmlTree. The new child node child becomes the n + 1st child of the resulting tree.

Examples

 > $\mathrm{with}\left(\mathrm{XMLTools}\right):$
 > $x:=\mathrm{XMLElement}\left("a",\left[\right],\left["some text",\mathrm{XMLElement}\left("b",\left[\right],"more text"\right),\mathrm{XMLElement}\left("c"\right)\right]\right)$
 ${x}{:=}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"more text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"c"}\right){,}\left[{}\right]{,}\left[{}\right]\right)\right]\right)$ (1)
 > $\mathbf{use}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{XMLTools}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{in}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{for}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}i\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{from}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}0\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{ContentModelCount}\left(x\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{print}\left(\mathrm{AddChild}\left(x,\mathrm{XMLElement}\left("d",\left[\right],"some child text"\right),i\right)\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end do}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end use}$
 ${\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"d"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some child text"}\right)\right]\right){,}{\mathrm{_XML_Text}}{}\left({"some text"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"more text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"c"}\right){,}\left[{}\right]{,}\left[{}\right]\right)\right]\right)$
 ${\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"d"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some child text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"more text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"c"}\right){,}\left[{}\right]{,}\left[{}\right]\right)\right]\right)$
 ${\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"more text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"d"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some child text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"c"}\right){,}\left[{}\right]{,}\left[{}\right]\right)\right]\right)$
 ${\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"a"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some text"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"b"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"more text"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"c"}\right){,}\left[{}\right]{,}\left[{}\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"d"}\right){,}\left[{}\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"some child text"}\right)\right]\right)\right]\right)$ (2)

 Please add your Comment (Optional) E-mail Address (Optional) What is ? This question helps us to combat spam