Retrieving text within 2 tags
Björnke von Gierke
bvg at mac.com
Sat Aug 2 08:11:02 EDT 2008
I use two different methods for getting text within tags. One gives
the first tag, the second gives every tag. The second one allows to
put every single occurrence into an element of an array, which is
highly useful in some cases. Also, neither change anything in the
original Data, removing the necessity to have it in memory twice.
Finally, due to the nature of html, they allow the open tag to contain
parameters, as many html tags can look like this: <div name="content"
width="20px">
For getting a single block of text that occurs only once, I'd use this:
on mouseUp
put url "http://whatever is correct for you/" into theData
put "myText" into theTag
put offset("<" & theTag, theData)+the number of chars in theTag +
1 into theStart
put offset("</" & theTag & ">", theData)-1 into theEnd
put char theStart to theEnd of theData
end mouseUp
I normally use a repeat loop to get stuff within all tags of a certain
sort, with setting line- and itemdelimiter. However, this is
conceptually a bit strange:
on mouseUp
put url "http://whatever is correct for you/" into theData
put "myText" into theTag
set the linedelimiter to "<"
set the itemdelimiter to ">"
put "" into theResult
put false into tagIsOpen
repeat for each line theLine in theData
if tagIsOpen then
if item 1 of theLine is ("/" & theTag) then
put false into tagIsOpen
next repeat
end if
put "<" & theLine after theResult
end if
if char 1 to (the number of chars in theTag) of theLine is
theTag then
put item 2 to -1 of theLine after theResult
put true into tagIsOpen
end if
end repeat
put theResult
end mouseUp
On 2 Aug 2008, at 01:34, mfstuart wrote:
>
> Hi all,
>
> RunRev: 2.90
> OS: WinXP
>
> How would I retrieve text that is within 2 tags, that has been put
> into a
> memory variable?
> The text originated from a web site, using command "put url theURL
> into
> tData".
> Such as:
>
> <MyText>
> This is some text I would like to
> retrieve. It is on many lines
> and all the text has to be return
> within the tags.
>
> Also, the text could have HTML formatting in it.
> </MyText>
>
> I don't know how to use the XML commands in rev as yet (a
> possibility), so I
> would like to use the text chunk commands to do so.
>
> TIA.
> Mark Stuart
> --
> View this message in context: http://www.nabble.com/Retrieving-text-within-2-tags-tp18784278p18784278.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> 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