revAddXMLNode - how to specify a parent node if multiple?

Jan Schenkel janschenkel at yahoo.com
Wed Aug 8 11:30:00 EDT 2012


You need to use brackets and indices in the path to the parent node.

Here's a quick example to explain it:
- create a new stack
- drop a field onto it
- drop a button onto it and set its script to
##on mouseUp
   local tXMLText,tXMLTree
   put "<?xml version=" & quote & "1.0" & quote & "?>" & return & \
         "<products />" into tXMLText
   put revCreateXMLTree(tXMLText,false,true,false) into tXMLTree
   --
   local tRootNode, tCurrentNode
   put revXMLRootNode(tXMLTree) into tRootNode
   repeat with tIndex = 1 to 3
      revAddXMLNode tXMLTree, tRootNode, "productidentifier", empty, "after"
      put tRootNode & "/productidentifier[" & tIndex & "]" into tCurrentNode
      revAddXMLNode tXMLTree, tCurrentNode, "b221", tIndex
   end repeat
   --
   put revXMLText(tXMLTree, empty, true) into field 1
   revDeleteXMLTree tXMLTree
end mouseUp
##

Now click on the button and you should see the following text appear:
##
<?xml version="1.0"?>
<products>
  <productidentifier><b221>1</b221></productidentifier>
  <productidentifier><b221>2</b221></productidentifier>
  <productidentifier><b221>3</b221></productidentifier>
</products>

##


HTH,


Jan Schenkel.


=====
Quartam Reports & PDF Library for LiveCode
www.quartam.com


=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)





More information about the use-livecode mailing list