HTML tags in XML
Mark Brownell
gizmotron at earthlink.net
Wed Mar 22 12:52:08 EST 2006
>From: Devin Asay <devin_asay at byu.edu>
>Hi Folks,
>
>Is it possible to store html styled text in an xml document and then
>successfully retrieve the text with html markup intact?
>
>I'm working on an application where I need to save styled text in an
>XML document. I can successfully insert the htmlText of the styled
>field into the xml document so I end up with a node that looks like
>this:
>
><comments>
>Here are my comments.
>Some of the text is colored <font color="#FF0000">red</font> &
><font color="#0000FF">blue</font>
></comments>
>
>However, when I read this node in with the revXMLNodeContents()
>function the html tags are stripped out and all I get is naked text.
>Here's a code snippet:
>
>Devin
Use a pull-parser function (see below)
Example :
put PNLPgetElement("<pullThisTag>", "</pullThisTag>", tPullThis) into tPullThisTag
for elements:
function PNLPgetElement tStTag, tEdTag, stngToSch
put empty into zapped
put the number of chars in tStTag into dChars
put offset(tStTag,stngToSch) into tNum1
put offset(tEdTag,stngToSch) into tNum2
if tNum1 < 1 then
return "error"
exit PNLPgetElement
end if
if tNum2 < 1 then
return "error"
exit PNLPgetElement
end if
put char (tNum1 + dChars) to (tNum2 - 1) of stngToSch into zapped
return zapped
end PNLPgetElement
For an array of elements:
function getPNLPelements tStartTag, tEndTag, StringToSearch
put empty into tArray
put 0 into tStart1
put 0 into tStart2
put 1 into tElementNum
put the number of chars in tStartTag into dChars
repeat
put offset(tStartTag,StringToSearch,tStart1) into tNum1
put (tNum1 + tStart1) into tStart1
if tNum1 < 1 then exit repeat
put offset(tEndTag,StringToSearch,tStart2) into tNum2
put (tNum2 + tStart2) into tStart2
if tNum2 < 1 then exit repeat
--if tNum2 < tNum1 then exit repeat
put char (tStart1 + dChars) to (tStart2 - 1) of StringToSearch into zapped
put zapped into tArray[tElementNum]
add 1 to tElementNum
end repeat
return tArray
end getPNLPelements
More information about the use-livecode
mailing list