Contents of a field to XML...

Jan Schenkel janschenkel at yahoo.com
Wed Jan 10 14:16:59 EST 2007


--- David Bovill <david at openpartnership.net> wrote:
> Related to the lastpost I'm looking for the most
> general way to take any
> text in field an put it into an XML document?
> 
> I was hoping that htmltext would do the trick but is
> is not xHTML compliant,
> so I am thinking about using the unicode functions
> and UTF8 - would that be
> the way to go? And if so what are the issues in
> terms of making the document
> cross platform?
> 

Hi David,

A while ago I needed a way to make the htmlText of a
field XML-compliant. The main difficulty was in the
img tags which aren't closed. Here's what I came up
with:
##
function htmlText2xml pHtmlText
  put "<img src=" & quote into kOPENTAG
  put quote & ">" into kCLOSETAG
  --  
  put 0 into tStart
  put offset(kOPENTAG,pHtmlText,tStart) into tOffset
  repeat until tOffset = 0
    put offset(kCLOSETAG,pHtmlText,tStart+tOffset)
into tEnd
    put " /" after char tStart+tOffset+tEnd of
pHtmlText
    add tOffset + 10 to tStart
    put offset(kOPENTAG,tText,tStart) into tOffset
  end repeat
  return "<?xml version=" & quote & "1.0" & quote &
"?> & return & \
      "<html>" & return & pHtmlText & return &
"</html>"
end htmlText2xml
##

As the htmlText will automatically replace any
non-Latin characters with enity numbers, you don't
have to worry too much about Unicode.
Some XML parsers will complain that these entities
aren't specified anywhere. But at least you can
process the resulting xml with Rev's xml library
calls.

Hope this helped,

Jan Schenkel.

Quartam Reports for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


 
____________________________________________________________________________________
Yahoo! Music Unlimited
Access over 1 million songs.
http://music.yahoo.com/unlimited



More information about the use-livecode mailing list