ABS383B ; Generate a DTD for responses based on a selected file or one
of its subfiles [ 12/05/1999 10:59 PM ]
; For CECS383: The Science and Techonology of the World
Wide Web by Arthur B. Smith (754104)
GenRDTD(FNum,Dest) ; Generate a Response DTD for the file (and subfiles) specified by
FNum. Save it in file Dest
New
SFNum
Set
U="^"
Open
51:(Dest:"W") ; Open the specifed destination for writing
Use
51
Do
MkTree^ABS383A(FNum) ; Make sure our data on this file is up-to-date
Write
"<!-- Document Type Definition for responses based
on File "
Write
FNum," (",$Piece(^ABS383(FNum),U,2),")
-->",!
; The top level element, Response, is zero or more of any
of the files/subfiles
Write
"<!ELEMENT
Response ("
Set
SFNum=FNum-0.00001,First=1
For Set SFNum=$Order(^ABS383("FNUM",SFNum)) Quit:(SFNum\1)'=FNum Do
. If
'First Write "|"
. Else Set First=0
. Write
"(",$$ElemNam(^ABS383("FNUM",SFNum)),"*)"
Write
")>",!!
; $QUERY through
all the fields and subfiles
Set
Elem="^ABS383("_(FNum-0.00001)_")"
For Set Elem=$Query(@Elem) Quit:Elem="" Quit:$QSubscript(Elem,1)'=FNum Do
. Set
Type=$Piece(@Elem,U,3)
. If
Type="FILE" Do ; This is a FILE (multiple field)
. . New
First,SubElem,SType
. . Write
"<!ELEMENT
",$$ElemNam(Elem)," ("
. . Set
SubElem=Elem,First=1
. . For Set SubElem=$Query(@SubElem) Quit:SubElem="" Quit:$QSubscript(SubElem,$QLength(Elem))'=$QSubscript(Elem,$QLength(Elem)) Do
. . . If 'First
Write ", "
. . . Else Set First=0
. . . Write $$ElemNam(SubElem)
. . . Set SType=$Piece(SubElem,U,3)
. . . If SType'="FILE" Write "?"
. . . Else Write "*"
. . Write
")>",!
. . Write
"<!ATTLIST
",$$ElemNam(Elem)," IENS
CDATA #REQUIRED>",!!
. Else Do ; Not
FILE so is a single field
. . ; For now, just assume that they are all PCDATA --
may get smarter later
. . Write
"<!ELEMENT
",$$ElemNam(Elem),"
(#PCDATA)>",!!
Close
51
Quit
ElemNam(Entry) ; EXTRINSIC FUNCTION
; Given a name which is an entry in ^ABS383, return the
element name for that entry
New
Result,P
Set
U="^"
Set
P="-"
Set
Result=$Char(64+$QLength(Entry)) ; Initial letter to get depth
Set
Result=Result_P_$Piece(@Entry,U,1)_P_$Translate($Piece(@Entry,U,2),"
,/\()[]{};!@#$%^&*-=+|<>?","__________________________")
Quit
Result