Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,4 +1,5 @@
|
|||
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <code><Character></code> elements each with a name attributes and each enclosing its remarks. All <code><Character></code> elements are to be enclosed in turn, in an outer <code><CharacterRemarks></code> element.
|
||||
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of <code><Character></code> elements each with a name attributes and each enclosing its remarks.
|
||||
All <code><Character></code> elements are to be enclosed in turn, in an outer <code><CharacterRemarks></code> element.
|
||||
|
||||
As an example, calling the function with the three names of:
|
||||
<pre>
|
||||
|
|
@ -22,4 +23,5 @@ The document may include an <tt><?xml?></tt> declaration and document type decla
|
|||
Note: the example is chosen to show correct escaping of XML strings.
|
||||
Note too that although the task is written to take two lists of corresponding data, a single mapping/hash/dictionary of names to remarks is also acceptable.
|
||||
|
||||
'''Note to editors:''' Program output with escaped characters will be viewed as the character on the page so you need to 'escape-the-escapes' to make the RC entry display what would be shown in a plain text viewer (See [[Talk:XML_Creation#Escaping_Escapes|this]]). Alternately, output can be placed in <nowiki><lang xml></lang></nowiki> tags without any special treatment.
|
||||
'''Note to editors:''' Program output with escaped characters will be viewed as the character on the page so you need to 'escape-the-escapes' to make the RC entry display what would be shown in a plain text viewer (See [[Talk:XML_Creation#Escaping_Escapes|this]]).
|
||||
Alternately, output can be placed in <nowiki><lang xml></lang></nowiki> tags without any special treatment.
|
||||
|
|
|
|||
112
Task/XML-Output/Bracmat/xml-output.bracmat
Normal file
112
Task/XML-Output/Bracmat/xml-output.bracmat
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
( ( 2XML
|
||||
= PCDATAentities attributeValueEntities doAll doAttributes
|
||||
, xml
|
||||
. ( attributeValueEntities
|
||||
= a c
|
||||
. @( !arg
|
||||
: ?a
|
||||
(("<"|"&"|\"):?c)
|
||||
?arg
|
||||
)
|
||||
& !a
|
||||
"&"
|
||||
( !c:"<"<
|
||||
| !c:"&"&
|
||||
| quot
|
||||
)
|
||||
";"
|
||||
attributeValueEntities$!arg
|
||||
| !arg
|
||||
)
|
||||
& ( PCDATAentities
|
||||
= a c
|
||||
. @( !arg
|
||||
: ?a
|
||||
(("<"|"&"|">"):?c)
|
||||
?arg
|
||||
)
|
||||
& !a
|
||||
"&"
|
||||
( !c:"<"<
|
||||
| !c:"&"&
|
||||
| gt
|
||||
)
|
||||
";"
|
||||
PCDATAentities$!arg
|
||||
| !arg
|
||||
)
|
||||
& ( doAttributes
|
||||
= a v
|
||||
. !arg:(?a.?v) ?arg
|
||||
& " "
|
||||
PCDATAentities$!a
|
||||
"=\""
|
||||
attributeValueEntities$!v
|
||||
\"
|
||||
doAttributes$!arg
|
||||
|
|
||||
)
|
||||
& ( doAll
|
||||
= xml first A B C att XML
|
||||
. !arg:?xml
|
||||
& :?XML
|
||||
& whl
|
||||
' ( !xml:%?first ?xml
|
||||
& ( !first:(?A.?B)
|
||||
& ( !B:(?att,?C)
|
||||
& !XML
|
||||
( !C:
|
||||
& "<" !A doAttributes$!att " />\n"
|
||||
| "<"
|
||||
!A
|
||||
doAttributes$!att
|
||||
">"
|
||||
doAll$!C
|
||||
"</"
|
||||
!A
|
||||
">\n"
|
||||
)
|
||||
: ?XML
|
||||
| !A
|
||||
: ( "!"&!XML "<!" !B ">":?XML
|
||||
| "!--"
|
||||
& !XML "<!--" !B "-->":?XML
|
||||
| "?"&!XML "<?" !B "?>\n":?XML
|
||||
| "![CDATA["
|
||||
& !XML "<![CDATA[" !B "]]>":?XML
|
||||
| "!DOCTYPE"
|
||||
& !XML "<!DOCTYPE" !B ">":?XML
|
||||
| ?
|
||||
& !XML "<" !A doAttributes$!B ">":?XML
|
||||
)
|
||||
)
|
||||
| !XML PCDATAentities$!first:?XML
|
||||
)
|
||||
)
|
||||
& str$!XML
|
||||
)
|
||||
& doAll$!arg
|
||||
)
|
||||
& ( makeList
|
||||
= characters name names remark remarks
|
||||
. !arg:(?names.?remarks)
|
||||
& :?characters
|
||||
& whl
|
||||
' ( (!names.!remarks)
|
||||
: (%?name ?names.%?remark ?remarks)
|
||||
& !characters (Character.(name.!name),!remark)
|
||||
: ?characters
|
||||
)
|
||||
& ("?".xml) (CharacterRemarks.,!characters)
|
||||
)
|
||||
& put
|
||||
$ ( 2XML
|
||||
$ ( makeList
|
||||
$ ( April "Tam O'Shanter" Emily
|
||||
. "Bubbly: I'm > Tam and <= Emily"
|
||||
"Burns: \"When chapman billies leave the street ...\""
|
||||
"Short & shrift"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
34
Task/XML-Output/Euphoria/xml-output.euphoria
Normal file
34
Task/XML-Output/Euphoria/xml-output.euphoria
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
function xmlquote(sequence s)
|
||||
sequence r
|
||||
r = ""
|
||||
for i = 1 to length(s) do
|
||||
if s[i] = '<' then
|
||||
r &= "<"
|
||||
elsif s[i] = '>' then
|
||||
r &= ">"
|
||||
elsif s[i] = '&' then
|
||||
r &= "&"
|
||||
elsif s[i] = '"' then
|
||||
r &= """
|
||||
elsif s[i] = '\'' then
|
||||
r &= "'"
|
||||
else
|
||||
r &= s[i]
|
||||
end if
|
||||
end for
|
||||
return r
|
||||
end function
|
||||
|
||||
constant CharacterRemarks = {
|
||||
{"April", "Bubbly: I'm > Tam and <= Emily"},
|
||||
{"Tam O'Shanter", "Burns: \"When chapman billies leave the street ...\""},
|
||||
{"Emily", "Short & shrift"}
|
||||
}
|
||||
|
||||
puts(1,"<CharacterRemarks>\n")
|
||||
for i = 1 to length(CharacterRemarks) do
|
||||
printf(1," <CharacterName=\"%s\">",{xmlquote(CharacterRemarks[i][1])})
|
||||
puts(1,xmlquote(CharacterRemarks[i][2]))
|
||||
puts(1,"</Character>\n")
|
||||
end for
|
||||
puts(1,"</CharacterRemarks>\n")
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
(load "@lib/xm.l")
|
||||
(load "@lib/xml.l")
|
||||
|
||||
(de characterRemarks (Names Remarks)
|
||||
(xml
|
||||
|
|
|
|||
|
|
@ -1,34 +1,34 @@
|
|||
/*REXX program to create a list of character names & remarks. */
|
||||
charname.=
|
||||
charname.1="April"
|
||||
charname.2="Tam O'Shanter"
|
||||
charname.3="Emily"
|
||||
do i=1 while charname.i\==''
|
||||
say 'charname' i '=' charname.i
|
||||
end /*i*/; say
|
||||
remark.=
|
||||
remark.1="I'm > Tam and <= Emily"
|
||||
remark.2="When chapman billies leave the street ..."
|
||||
remark.3="Short & shift"
|
||||
do k=1 while remark.k\==''
|
||||
say ' remark' k '=' remark.k
|
||||
end /*k*/; say
|
||||
items=0
|
||||
header='CharacterRemarks'
|
||||
header=header'>'
|
||||
/*REXX program creates an HTML list of character names and remarks. */
|
||||
charname. =
|
||||
charname.1 = "April"
|
||||
charname.2 = "Tam O'Shanter"
|
||||
charname.3 = "Emily"
|
||||
do i=1 while charname.i\==''
|
||||
say 'charname' i '=' charname.i
|
||||
end /*i*/; say
|
||||
remark. =
|
||||
remark.1 = "I'm > Tam and <= Emily"
|
||||
remark.2 = "When chapman billies leave the street ..."
|
||||
remark.3 = "Short & shift"
|
||||
do k=1 while remark.k\==''
|
||||
say ' remark' k '=' remark.k
|
||||
end /*k*/; say
|
||||
items = 0
|
||||
header = 'CharacterRemarks'
|
||||
header = header'>'
|
||||
|
||||
do j=1 while charname.j\==''
|
||||
do j=1 while charname.j\==''
|
||||
_=charname.j
|
||||
if j==1 then call create '<'header
|
||||
if j==1 then call create '<'header
|
||||
call create ' <Character name="' ||,
|
||||
char2xml(_)'">"' ||,
|
||||
char2xml(remark.j)'"</Character>'
|
||||
end /*j*/
|
||||
|
||||
if create.0\==0 then call create '</'header
|
||||
if create.0\==0 then call create '</'header
|
||||
|
||||
do m=1 for create.0
|
||||
say create.m
|
||||
do m=1 for create.0
|
||||
say create.m /*display the Mth entry to term*/
|
||||
end /*m*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────CREATE subroutine───────────────────*/
|
||||
|
|
@ -38,28 +38,26 @@ create.0=items /*indicate how many items in list*/
|
|||
return
|
||||
/*──────────────────────────────────XML_ subroutine─────────────────────*/
|
||||
xml_: parse arg _ /*make an XML entity (&xxxx;) */
|
||||
if pos(_,x)\==0 then return changestr(_,x,"&"arg(2)";")
|
||||
return x
|
||||
if pos(_,x)\==0 then return changestr(_,x,"&"arg(2)";")
|
||||
return x
|
||||
/*──────────────────────────────────CHAR2XML subroutine─────────────────*/
|
||||
char2xml: procedure; parse arg x
|
||||
a=pos('&',x)\==0 /*ampersands have to be treated special.*/
|
||||
b=pos(';',x)\==0 /*semicolons have to be treated special.*/
|
||||
char2xml: procedure; parse arg x
|
||||
a=pos('&',x)\==0 /* & have to be treated special.*/
|
||||
b=pos(';',x)\==0 /* ; " " " " " */
|
||||
xml0=0
|
||||
|
||||
if a\==0 then do
|
||||
a=1 /*below, find a free character to translate freely.*/
|
||||
do j=0 to 254; ?=d2c(j); if pos(?,x)==0 then leave; end
|
||||
x=translate(x,?,"&");xml0=j+1
|
||||
end
|
||||
|
||||
if b\==0 then do
|
||||
b=1 /*below, find a free character to translate freely.*/
|
||||
do j=xml0 to 254; ??=d2c(j); if pos(??,x)==0 then leave; end
|
||||
x=translate(x,??,";")
|
||||
end
|
||||
/*Following are a few of the chars in */
|
||||
/*the DOS (DOS under Windows) codepage.*/
|
||||
|
||||
/* [↓] find a free character ···*/
|
||||
if a then do /* ··· translate freely·*/
|
||||
do j=0 to 254; ?=d2c(j); if pos(?,x)==0 then leave; end
|
||||
x=translate(x,?,"&"); xml0=j+1
|
||||
end
|
||||
/* [↓] find a free character ···*/
|
||||
if b then do /* ··· translate freely·*/
|
||||
do j=xml0 to 254; ??=d2c(j); if pos(??,x)==0 then leave; end
|
||||
x=translate(x,??,";")
|
||||
end
|
||||
/*Following are a few of the */
|
||||
/*characters in the DOS (or DOS */
|
||||
/*Windows) codepage 437 */
|
||||
x=XML_('♥',"hearts") ; x=XML_('â',"ETH") ; x=XML_('ƒ',"fnof") ; x=XML_('═',"boxH")
|
||||
x=XML_('♦',"diams") ; x=XML_('â','#x00e2') ; x=XML_('á',"aacute"); x=XML_('╬',"boxVH")
|
||||
x=XML_('♣',"clubs") ; x=XML_('â','#x00e9') ; x=XML_('á','#x00e1'); x=XML_('╧',"boxHu")
|
||||
|
|
@ -113,6 +111,6 @@ x=XML_('é',"eacute") ; x=XML_('¢',"cent") ; x=XML_('╩',"boxHU")
|
|||
x=XML_('é','#x00e9') ; x=XML_('£',"pound") ; x=XML_('╦',"boxHD") ; x=XML_('²',"sup2")
|
||||
x=XML_('â',"acirc") ; x=XML_('¥',"yen") ; x=XML_('╠',"boxVR") ; x=XML_('■',"squart ")
|
||||
|
||||
if a then x=xml_(?,"amp") /*if we had an ampersand, translate it now.*/
|
||||
if b then x=xml_(??,"semi") /*if we had a semicolon, translate it now.*/
|
||||
if a then x=xml_(?,"amp") /*if there was an ampersand, translate it*/
|
||||
if b then x=xml_(??,"semi") /* " " " " semicolon, " "*/
|
||||
return x
|
||||
|
|
|
|||
|
|
@ -6,5 +6,4 @@ def characterRemarks(names: List[String], remarks: List[String]) = <CharacterRem
|
|||
{ names zip remarks map { case (name, remark) => <Character name={name}>{remark}</Character> } }
|
||||
</CharacterRemarks>
|
||||
|
||||
|
||||
characterRemarks(names, remarks)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue