copying an xml node

Jim Ault JimAultWins at yahoo.com
Sat Feb 11 12:23:10 EST 2006


On 2/10/06 7:54 PM, "Martin Blackman" <martinblackman at gmail.com> wrote:

> 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 ?
> 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?

--Not sure it is simpler, if your way works.  You might try
replace "<" with "<"&cr in xmlVar
--which would put each tag on its own line
--then
filter xmlVar without "/*"
--which would purge the closing tag lines
filter xmlVar with "KEYWORD *"
--which would keep only those lines beginning with the keyword
filter xmlVar without "*=*"
--which would purge any lines with an attribute,
--     assuming no data included an = sign (dangerous)
--so maybe 
filter xmlVar without "*="&quote&"*"
filter xmlVar without "*= "&quote&"*"
--note the space in the second filter cmd to catch both syntax variations

There are also RegEx solutions for grabbing tags and content, but the
specifics are required to build the best solution.  So much of XML is
redundant, it is difficult to get just what you want.

You could even try a repeat loop that would modify your xmlVar by installing
a sequence of ID numbers at each tag (as an attribute?) that would allow you
to precisely locate tags now and in the future.

Just no sure what your work flow is.

Hope this helps trigger the ultimate solution for you.

Jim Ault
Las Vegas

On 2/10/06 7:54 PM, "Martin Blackman" <martinblackman at gmail.com> wrote:

> 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
> tnode!
>   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
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list