copying an xml node

Martin Blackman martinblackman at
Fri Feb 10 22:54:04 EST 2006

If I want to copy an XML node from one tree and put it into another, is
there an easy way to do it using transcript ?
I thought at first I could open my saved XML tree as a text file and find &
copy the line of interest, but it seems there are no returns at the end of
each tag.
So I rolled my own function (see below) to return a node together with its
attributes and their values as text, from an XML tree in memory. This text
could then be placed into the other tree with revAppendXML.  Has anyone got
a simpler suggestion?

function copyXMLnode tID,tnode
  --copy the text and attributes of a node and return as text. Rev doesn't
seem to have this function.
  put revXMLNodeContents(tID,tnode) into tCont
  --beware of (unconfirmed) Rev bug 3072 if there are nested elements within
  put revXMLAttributes(tID,tnode,tab,return) into tAtts
  set the itemdel to "/"; put item -1 of tnode into tnode --change it to the
tag name only
  put offset("[",tnode) into tcharloc --"[]" used to single out multiple
nodes with same name
  if tcharloc > 0 then put char 1 to (tcharloc -1) of tnode into tnode
  set the itemdel to tab
  repeat for each line tline in tAtts
    put space&(item 1 of tline)&"="&quote&(item 2 of tline)&quote after Atts

  end repeat
  return "<"&tnode&Atts&">"&tCont&"</"&tnode&">"
end copyXMLnode

More information about the Use-livecode mailing list