addnode
addnode |
Purpose
Synopsis
function addnode(doc:xmldoc, n:integer, where:integer, type:integer, name:string, value:text):integer
function addnode(doc:xmldoc, n:integer, where:integer, type:integer, nameval:string|text):integer
function addnode(doc:xmldoc, n:integer, type:integer, name:string, value:text):integer
function addnode(doc:xmldoc, n:integer, type:integer, nameval:string|text):integer
function addnode(doc:xmldoc, n:integer, type:integer):integer
function addnode(doc:xmldoc, n:integer, name:string, value:text|string|boolean|integer|real):integer
Arguments
doc
|
Document to use
|
||||||||||||
n
|
Node number where to attach the new node
|
||||||||||||
where
|
How to attach the new node to the node
n:
When the function is used without this parameter,
XML_LASTCHILD is assumed.
|
||||||||||||
type
|
Type of node to add:
When the function is used without this parameter,
XML_ELT is assumed.
|
||||||||||||
name
|
Name associated to the new node. Only
element and
processing instruction nodes have a name
|
||||||||||||
value
|
Value associated to the new node. An
element node does not have any value: if this parameter is provided for a node of this type, an additional
text node with the specified value is added as the first child of the new node
|
||||||||||||
nameval
|
If the type is
XML_ELT or
XML_PINST this parameter is used as the name of this node. Otherwise it is the value of the new node
|
Return value
Number of the newly created node within the document.
Example
The following code extract appends a new node 'employee' as last child to the node
APAC. It shows how to use diffrent versions of
addnode for the creation of descendants of the new node.
declarations DB: xmldoc APAC, NewPers, n, k: integer end-declarations APAC:= getnode(DB, "personnelList/region[@id='APAC']") ! Append a new node to 'APAC' and set its attribute 'id': NewPers:= addnode(DB, APAC, XML_LASTCHILD, XML_ELT, "employee") setattr(DB, NewPers, "id", "T432") ! Create a comment: n:= addnode(DB, NewPers, XML_COM, "This is a new employee") ! Add 2 nodes containing the specified text (nodes): n:= addnode(DB, NewPers, XML_ELT, "startDate", text(2012)) n:= addnode(DB, NewPers, XML_ELT, "name", "Tim") ! Add an empty node, then set its contents: n:= addnode(DB, NewPers, XML_ELT, "address") setvalue(DB, n, "Sydney") ! Add an empty node, then create its contents as a text node: n:= addnode(DB, NewPers, XML_ELT, "language") k:= addnode(DB, n, XML_TXT, "English")
XML resulting from this code:
<employee id="T432"> <!--This is a new employee--> <startDate>2012</startDate> <name>Tim</name> <address>Sydney</address> <language>English</language> </employee>
Further information
1. An element or processing instruction node must be named: trying to create a node of these types with an empty name will cause an error.
2. It is not possible to add attributes with this function. Use
setattr for this purpose.
Related topics
Module