copying an xml node

Martin Blackman martinblackman at gmail.com
Wed Feb 15 07:10:59 EST 2006


Thanks very much for the reply Jim and sorry for not responding earlier.
I guess I just wanted to speed up access time for information stored
in an xml file, by making a small subset of a larger file -there are
already ID attributes for each tag but my program will be making
repeated visits to the data.  Come to think of it, maybe I could put
the equivalent info into a global var or cust prop, but I have
routines written around the tree structure and its easy to keep with
them.

regards
Martin


On 12/02/06, Jim Ault <JimAultWins at yahoo.com> wrote:
> 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
>
>
> _______________________________________________
> 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