Home
About
Agents
CGIs
Mac
Macros
Misc
Stories
Suites
Websites
Outline
Frontier
Scripting

scriptingNewsToXML

Some people asked to see how we create the XML version of Scripting News, and the script embedded in this page has the complete answer.

First, you need to get the Scripting News source code from this page.

This is not for newbies.

Dave Winer
8/7/98

Listing

on scriptingNewsToXML (adroutline)
«called from dweb.home.getDayText
local (folder = dweb.home.["#ftpSite"].folder)
local (domirror = false, mirrorfolder = "H:\\apache\\htdocs\\")
local (pc = file.getPathChar ())
on encodeWithAmpersands (s)
s = string.replaceall (s, "&", "&")
s = string.replaceall (s, "<", "<")
return (s)
on outlineToXML (adroutline)
on extractLinks (s, adrlinks, adrlines)
local (links = {}, lines = {}, pat = "<a href=\"", ix, lefthalf)
loop
ix = string.patternmatch (pat, s)
if ix == 0
break
lefthalf = string.mid (s, 1, ix - 1)
s = string.delete (s, 1, ix + sizeof (pat) - 1)
ix = string.patternmatch ("\"", s) //the end of the url
url = string.mid (s, 1, ix - 1)
s = string.delete (s, 1, ix)
if s [1] == ">"
s = string.delete (s, 1, 1)
ix = string.patternmatch ("</a>", s)
linetext = string.mid (s, 1, ix - 1)
s = s - "</a>"
s = lefthalf + s
links = links + url
lines = lines + linetext
adrlinks^ = links
adrlines^ = lines
return (s)
local (xmltext = "", indent = 0)
on add (s)
xmltext = xmltext + string.filledstring ("\t", indent) + s + "\r\n"
add ("<?xml version=\"1.0\"?>")
add ("<!DOCTYPE scriptingNews SYSTEM \"http://www.scripting.com/dtd/scriptingNews.dtd\">")
add ("<scriptingNews>"); indent++
bundle //add the <header> info
add ("<header>"); indent++
local (s = "Copyright 1997")
local (day, month, year, hour, minute, second)
date.get (clock.now (), @day, @month, @year, @hour, @minute, @second)
if year > 1997
s = s + "-" + year
add ("<copyright>" + s + " UserLand Software, Inc.</copyright>")
add ("<scriptingNewsVersion>1.0</scriptingNewsVersion>")
local (pubDate)
bundle //derive the publication date from the address of the outline
local (nomad = adroutline)
day = number (nameOf (nomad^) - "News")
nomad = parentOf (nomad^)
month = number (nameOf (nomad^))
nomad = parentOf (nomad^)
year = number (nameOf (nomad^))
if year < 2000
year = year + 1900
hour = 0; minute = 0; second = 0
pubDate = date.set (day, month, year, hour, minute, second)
add ("<pubDate>" + date.netStandardString (pubDate) + "</pubDate>")
add ("<lastBuildDate>" + date.netStandardString (clock.now ()) + "</lastBuildDate>")
add ("<docs>" + "http://www.scripting.com/frontier5/xml/scriptingNews.html" + "</docs>")
add ("</header>"); indent--
local (oldtarget = target.set (adroutline))
local (oldcursor = op.getcursor ())
op.firstsummit ()
op.fullexpand ()
on getlinetext () //get the text of the cursor and all its subheads
local (linetext = op.getlinetext ())
local (s = "")
s = s + linetext
if op.go (right, 1)
loop
s = s + " " + getlinetext () //recurse
if not op.go (down, 1)
break
op.go (left, 1)
s = string.popTrailing (s, ' ')
return (s)
loop
local (s = getlinetext ())
if s != "" //skip blank lines
local (links, lines, i) //parallel lists
s = extractlinks (s, @links, @lines)
add ("<item>"); indent++
add ("<text>" + encodeWithAmpersands (s) + "</text>")
for i = 1 to sizeof (links)
add ("<link>"); indent++
add ("<url>" + encodeWithAmpersands (links [i]) + "</url>")
add ("<linetext>" + encodeWithAmpersands (lines [i]) + "</linetext>")
add ("</link>"); indent--
add ("</item>"); indent--
if not op.go (down, 1)
break
op.setcursor (oldcursor)
target.set (oldtarget)
add ("</scriptingNews>"); indent--
return (xmltext)
bundle //derive the folder from the address of the outline
local (nomad = parentOf (adroutline^), s = nameOf (nomad^) + pc)
nomad = parentOf (nomad^)
s = nameOf (nomad^) + pc + s
folder = folder + s
mirrorfolder = mirrorfolder + s
local (s = outlineToXML (adroutline))
local (f = folder + nameOf (adroutline^) + ".xml")
local (mirrorf = mirrorfolder + nameOf (adroutline^) + ".xml")
file.sureFilePath (f)
file.writeWholeFile (f, s)
if domirror
file.sureFilePath (mirrorf)
file.writeWholeFile (mirrorf, s)
return (f)
bundle //build one XML file
local (f = scriptingNewsToXML (@dweb.home.["98"].["08"].News20))
dialog.alert (f)
«bundle //build all XMLs
«local (adryeartable = @dweb.home.["97"], i, j)
«for j = 1 to sizeof (adryeartable^)
«local (adrtable = @adryeartable^ [j])
«if (nameof (adrtable^) != 11) and (nameof (adrtable^) != 12)
«continue
«for i = 1 to sizeof (adrtable^)
«local (adr = @adrtable^ [i])
«if nameOf (adr^) beginswith "News"
«msg (adr)
«scriptingNewsToXML (adr)


This is a fat web page containing dweb.home.tools.scriptingNewsToXML. More info on fat pages here.

© copyright 1997-98 UserLand Software. This page was originally posted on 8/7/98; 11:25:59 AM and it was last built on 9/11/98; 9:24:07 AM. Webmaster: dave@userland.com.