addnode


Purpose
Add a node to a document tree.
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
Node number where to attach the new node
where 
How to attach the new node to the node n:
XML_FIRST 
as the first element of the list where node n is located
XML_LAST 
as the last element of the list where node n is located
XML_NEXT 
after node n
XML_FIRSTCHILD 
as the first child of node n (node n must be an element)
XML_LASTCHILD 
as the last child of node n (node n must be an element)
When the function is used without this parameter, XML_LASTCHILD is assumed.
type 
Type of node to add:
XML_ELT 
an element
XML_TXT 
a text block
XML_CDATA 
a CDATA section
XML_COM 
a comment
XML_DATA 
non interpreted data
XML_PINST 
processing instruction
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
copynode, delnode
Module
mmxml


If you have any comments or suggestions about these pages, please send mail to support@fico.com.

© Copyright 2001-2013 Fair Isaac Corporation. All rights reserved.