ABS383C       ; Generate a DTD for queries based on a selected file or one of its subfiles [ 12/05/1999  10:58 PM ]

            ; For CECS383: The Science and Techonology of the World Wide Web by Arthur B. Smith (754104)

       

GenQDTD(FNum,Dest) ; Generate a Query 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 queries based on File "

        Write FNum," (",$Piece(^ABS383(FNum),U,2),") -->",!

            ; The top level element, Query, specifies a result file type, selection criteria and optional

            ; sorting criteria and project restrictions

        Write "<!ELEMENT Query (File, Select, Sort?, Project?)>",!!

            ; The (sub)file to be returned must be specified

        Write "<!ELEMENT File ("

        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^ABS383B(^ABS383("FNUM",SFNum)),")"

        Write ")>",!

            ; ...and the definitions of those files...

        Set SFNum=FNum-0.00001

        For  Set SFNum=$Order(^ABS383("FNUM",SFNum)) Quit:(SFNum\1)'=FNum  Do

        . Write "<!ELEMENT ",$$ElemNam^ABS383B(^ABS383("FNUM",SFNum))," EMPTY>",!

        Write !

            ; Next is the boolean grammar for selection criteria

        Write "<!ELEMENT Select (OR | AND | NOT | SAtom)>",!

        Write "<!ELEMENT OR     ((OR | AND | NOT | SAtom), (OR | AND | NOT | SAtom)+)>",!

        Write "<!ELEMENT AND    ((OR | AND | NOT | SAtom), (OR | AND | NOT | SAtom)+)>",!

        Write "<!ELEMENT NOT    (OR | AND | NOT | SAtom)>",!

        Write "<!ELEMENT SAtom  (Field, (GT|LT|GE|LE|EQ|NE|SA), Expr)>",!

        Write "<!ELEMENT GT EMPTY><!ELEMENT LT EMPTY><!ELEMENT GE EMPTY><!ELEMENT LE EMPTY>",!

        Write "<!ELEMENT EQ EMPTY><!ELEMENT NE EMPTY><!ELEMENT SA EMPTY>",!

        Write "<!ELEMENT Expr (#PCDATA)>",!!  ; Real generic for now!

            ; Set all the fields in to the 'Field' element

        Write "<!ELEMENT Field ( "

        Set Elem="^ABS383("_(FNum-0.00001)_")",First=1

        For  Set Elem=$Query(@Elem) Quit:Elem=""  Quit:$QSubscript(Elem,1)'=FNum  Do

        . If $Piece(@Elem,U,3)="FILE" Quit  ; This is a FILE (multiple field) -- not a valid selection for a select/sort criterion

        . If 'First Write " | "

        . Else  Set First=0

        . Write $$ElemNam^ABS383B(Elem)

        Write " )>",!!

            ; Now define each of those fields as EMPTY... (sheesh!)

        Set Elem="^ABS383("_(FNum-0.00001)_")"

        For  Set Elem=$Query(@Elem) Quit:Elem=""  Quit:$QSubscript(Elem,1)'=FNum  Do

        . If $Piece(@Elem,U,3)="FILE" Quit  ; This is a FILE (multiple field) -- not a valid selection for a select/sort criterion

        . Write "<!ELEMENT ",$$ElemNam^ABS383B(Elem)," EMPTY>",!

        Write !

        Write "<!ELEMENT Sort      (Field, (UP | DOWN))+>",!

        Write "<!ELEMENT UP        EMPTY>",!

        Write "<!ELEMENT DOWN      EMPTY>",!!

       

        Write "<!ELEMENT Project (Field+)>",!!

 

        Close 51

        Quit