regex help please

2012-02-09 Thread Klaus on-rev
Hi friends,

in my current project I need to deal with VERY small XML files 
with maybe up to 20 entries.

So using the XML external seems to be a bit overkill.

Some time ago I found a little reg ex here on the list which I turned
into a function and will return me everything inside of a given XML tag:
...
tag1bla bla/tag1
tag2more bla bla/tag2
...

So with this text above in tText and tag2 int tTag:

function mk_getXMLdata tText, tTag
   get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
   return tValue
end mk_getXMLdata

will give : more bla bla
So far so good, I even almost understand the reg ex ;-)

Now I am looking for another little snippet to (over) write something in(to) 
a certain TAG, know what I mean?

If someone could supply a nifty replacetext snippet that would be great! :-)
Thanks in advance!


Best

Klaus

--
Klaus Major
http://www.major-k.de
kl...@major.on-rev.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Andre Garzia
Klaus,

I used to work like that, doing little XML files with RegEx and matchText.
After working like that for a long time, I came to realize that there was
no advantage at all in my case. It was simpler to work with RevXML. The
problem with RegEx is all the little cases where it fails. I think you
should use RevXML, it might look overkill but it will cut your debug time a
lot.

Cheers
andre

On Thu, Feb 9, 2012 at 6:24 PM, Klaus on-rev kl...@major.on-rev.com wrote:

 Hi friends,

 in my current project I need to deal with VERY small XML files
 with maybe up to 20 entries.

 So using the XML external seems to be a bit overkill.

 Some time ago I found a little reg ex here on the list which I turned
 into a function and will return me everything inside of a given XML tag:
 ...
 tag1bla bla/tag1
 tag2more bla bla/tag2
 ...

 So with this text above in tText and tag2 int tTag:

 function mk_getXMLdata tText, tTag
   get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
   return tValue
 end mk_getXMLdata

 will give : more bla bla
 So far so good, I even almost understand the reg ex ;-)

 Now I am looking for another little snippet to (over) write something
 in(to)
 a certain TAG, know what I mean?

 If someone could supply a nifty replacetext snippet that would be great!
 :-)
 Thanks in advance!


 Best

 Klaus

 --
 Klaus Major
 http://www.major-k.de
 kl...@major.on-rev.com


 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode




-- 
http://www.andregarzia.com -- All We Do Is Code.
http://fon.nu -- minimalist url shortening service.
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Ken Corey

On 09/02/2012 20:24, Klaus on-rev wrote:

in my current project I need to deal with VERY small XML files
with maybe up to 20 entries.


Wait, didn't we just hear that you can't parse html (or XML) with 
regexps?  *grin*



function mk_getXMLdata tText, tTag
get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
return tValue
end mk_getXMLdata


Throwing caution to the winds, this probably does something similar to 
what you want without further regexp voodoo:


function mk_replaceXMLdata tText, tTag, tNewText
   put tText into tValue
   if matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue) then
  put replaceText(tText, \
tTagtValue/tTag,\
  tTagtNewText/tTag) into tValue
   end if
   return tValue
end mk_replaceXMLdata

And remember: zalgo is tony the pony! He's a comin!

-Ken

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Mark Wieder
Klaus,

What Andre said. Nonetheless, if you want to continue down the regex path, try
something like

 get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
 replace   tTagtValue /  tTag   with
tTagtNewValue /  tTag  
  in tText

-- 
 Mark Wieder




___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Klaus on-rev
Hi Andre,

Am 09.02.2012 um 21:38 schrieb Andre Garzia:

 Klaus,
 
 I used to work like that, doing little XML files with RegEx and matchText.
 After working like that for a long time, I came to realize that there was
 no advantage at all in my case. It was simpler to work with RevXML. The
 problem with RegEx is all the little cases where it fails. I think you
 should use RevXML, it might look overkill but it will cut your debug time a
 lot.

than you for your insight, but in this project I have complete control over the 
XML
and thus will not get any surprises :-)

 Cheers
 andre

Best

Klaus

--
Klaus Major
http://www.major-k.de
kl...@major.on-rev.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Klaus on-rev
Hi guys,

Am 09.02.2012 um 21:52 schrieb Mark Wieder:

 Klaus,
 
 What Andre said.

Sigh... :-)

 Nonetheless, if you want to continue down the regex path, try
 something like
 
 get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
 replace   tTagtValue /  tTag   with
tTagtNewValue /  tTag  
  in tText

well, I did not want to pass the text that I want to overwrite in the XML, 
which I do not now in that moment!
But this is neccesary in Mark's and zalgo/tony the coming ponys (? :-D ) 
scripts.

I only want to pass the XML text, the tagname and the NEW text to be place 
inside of these tags.
Any other hints?

 -- 
 Mark Wieder

Best

Klaus

--
Klaus Major
http://www.major-k.de
kl...@major.on-rev.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Andre Garzia
Klaus,

Since you have control, then instead of RegEx, you can go like

mynode
nodecontent
/mynode

All in different lines, then, you can just use lineOffset to find the start
node and the end node and copy or replace the data between those lines. It
is easier than RegEx.

On Thu, Feb 9, 2012 at 6:54 PM, Klaus on-rev kl...@major.on-rev.com wrote:

 Hi Andre,

 Am 09.02.2012 um 21:38 schrieb Andre Garzia:

  Klaus,
 
  I used to work like that, doing little XML files with RegEx and
 matchText.
  After working like that for a long time, I came to realize that there was
  no advantage at all in my case. It was simpler to work with RevXML. The
  problem with RegEx is all the little cases where it fails. I think you
  should use RevXML, it might look overkill but it will cut your debug
 time a
  lot.

 than you for your insight, but in this project I have complete control
 over the XML
 and thus will not get any surprises :-)

  Cheers
  andre

 Best

 Klaus

 --
 Klaus Major
 http://www.major-k.de
 kl...@major.on-rev.com


 ___
 use-livecode mailing list
 use-livecode@lists.runrev.com
 Please visit this url to subscribe, unsubscribe and manage your
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-livecode




-- 
http://www.andregarzia.com -- All We Do Is Code.
http://fon.nu -- minimalist url shortening service.
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Klaus on-rev
Hi Andre,

Am 09.02.2012 um 22:05 schrieb Andre Garzia:

 Klaus,
 
 Since you have control, then instead of RegEx, you can go like
 
 mynode
 nodecontent
 /mynode
 
 All in different lines, then, you can just use lineOffset to find the start
 node and the end node and copy or replace the data between those lines.
 It is easier than RegEx.

well, that's what I want to find out by myself, but can't without the 
appropriate reg ex ;-)


Best

Klaus

--
Klaus Major
http://www.major-k.de
kl...@major.on-rev.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Ken Corey

On 09/02/2012 21:00, Klaus on-rev wrote:

get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
replace   tTagtValue/  tTag   with
tTagtNewValue/  tTag  
  in tText


well, I did not want to pass the text that I want to overwrite in the XML,
which I do not now in that moment!
But this is neccesary in Mark's and zalgo/tony the coming ponys (? :-D ) 
scripts.

I only want to pass the XML text, the tagname and the NEW text to be place 
inside of these tags.
Any other hints?


You might take a look at the code again.

In both cases you hand in the whole XML text, the tag you want to 
replace, and the value you want to stuff into it.


The matchText function gets the current value in that tag.
Mark's replace above (or my replaceText) replace that, and return the 
result.


-Ken

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Ken Ray
 Nonetheless, if you want to continue down the regex path, try
 something like
 
 get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
 replace   tTagtValue /  tTag   with
   tTagtNewValue /  tTag  
 in tText
 
 well, I did not want to pass the text that I want to overwrite in the XML, 
 which I do not now in that moment!
 But this is neccesary in Mark's and zalgo/tony the coming ponys (? :-D 
 ) scripts.
 
 I only want to pass the XML text, the tagname and the NEW text to be place 
 inside of these tags.

Mark Weider's code will work for you, Klaus… the tValue is something that the 
matchText function FILLS with the current text inside the brackets, so you 
don't need to know it ahead of time.

The (.*?) is a way to capture what is between the tags, and the 3rd+ 
parameters to he matchTextFunction are variables that are provided to the 
function that get filled with whatever is being captured. The matchText 
function returns either 'true' (if it can find what you are looking for) or 
'false') if it can't. Mark's code above assumes a 'true' result by using get.

Here's an example that takes into account the possibility that you may not 
match what you're looking for:

put tagHello/tag into tData
if matchText(tData,(?s)tag(.*?)/tag,tValue) = true then
   put tValue  -- Since this matches, you'll get Hello in the msg box
else
   put No Match
end if
 

Ken Ray
Sons of Thunder Software, Inc.
Email: k...@sonsothunder.com
Web Site: http://www.sonsothunder.com/  

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Klaus on-rev
Hi friends,

thank you all for your help, i got it to work now!
Again thanks a lot!


Best

Klaus
--
Klaus Major
http://www.major-k.de
kl...@major.on-rev.com


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: regex help please

2012-02-09 Thread Bob Sneidar
Your training is almost complete. Destroy Darth Vader and take his place at my 
side! Mooo haah haah haha hahah ahah!

Bob


On Feb 9, 2012, at 12:24 PM, Klaus on-rev wrote:

 So with this text above in tText and tag2 int tTag:
 
 function mk_getXMLdata tText, tTag
   get matchText(tText,(?s)  tTag  (.*?)/  tTag  ,tValue)
   return tValue
 end mk_getXMLdata
 
 will give : more bla bla
 So far so good, I even almost understand the reg ex ;-)


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode