src/Pure/General/xml.ML
changeset 43791 5e9a1d71f94d
parent 43783 ef45eaf2775f
child 43797 fad7758421bf
equal deleted inserted replaced
43790:9bd8d4addd6e 43791:5e9a1d71f94d
    36   val header: string
    36   val header: string
    37   val text: string -> string
    37   val text: string -> string
    38   val element: string -> attributes -> string list -> string
    38   val element: string -> attributes -> string list -> string
    39   val output_markup: Markup.T -> Output.output * Output.output
    39   val output_markup: Markup.T -> Output.output * Output.output
    40   val string_of: tree -> string
    40   val string_of: tree -> string
       
    41   val pretty: int -> tree -> Pretty.T
    41   val output: tree -> TextIO.outstream -> unit
    42   val output: tree -> TextIO.outstream -> unit
    42   val parse_comments: string list -> unit * string list
    43   val parse_comments: string list -> unit * string list
    43   val parse_string : string -> string option
    44   val parse_string : string -> string option
    44   val parse_element: string list -> tree * string list
    45   val parse_element: string list -> tree * string list
    45   val parse_document: string list -> tree * string list
    46   val parse_document: string list -> tree * string list
   110   else (enclose "<" ">" (elem name atts), enclose "</" ">" name);
   111   else (enclose "<" ">" (elem name atts), enclose "</" ">" name);
   111 
   112 
   112 
   113 
   113 (* output *)
   114 (* output *)
   114 
   115 
   115 fun buffer_of tree =
   116 fun buffer_of depth tree =
   116   let
   117   let
   117     fun traverse (Elem ((name, atts), [])) =
   118     fun traverse _ (Elem ((name, atts), [])) =
   118           Buffer.add "<" #> Buffer.add (elem name atts) #> Buffer.add "/>"
   119           Buffer.add "<" #> Buffer.add (elem name atts) #> Buffer.add "/>"
   119       | traverse (Elem ((name, atts), ts)) =
   120       | traverse d (Elem ((name, atts), ts)) =
   120           Buffer.add "<" #> Buffer.add (elem name atts) #> Buffer.add ">" #>
   121           Buffer.add "<" #> Buffer.add (elem name atts) #> Buffer.add ">" #>
   121           fold traverse ts #>
   122           traverse_body d ts #>
   122           Buffer.add "</" #> Buffer.add name #> Buffer.add ">"
   123           Buffer.add "</" #> Buffer.add name #> Buffer.add ">"
   123       | traverse (Text s) = Buffer.add (text s);
   124       | traverse _ (Text s) = Buffer.add (text s)
   124   in Buffer.empty |> traverse tree end;
   125     and traverse_body 0 _ = Buffer.add "..."
   125 
   126       | traverse_body d ts = fold (traverse (d - 1)) ts;
   126 val string_of = Buffer.content o buffer_of;
   127   in Buffer.empty |> traverse depth tree end;
   127 val output = Buffer.output o buffer_of;
   128 
       
   129 val string_of = Buffer.content o buffer_of ~1;
       
   130 val output = Buffer.output o buffer_of ~1;
       
   131 
       
   132 fun pretty depth tree =
       
   133   Pretty.str (Buffer.content (buffer_of (Int.max (0, depth)) tree));
   128 
   134 
   129 
   135 
   130 
   136 
   131 (** XML parsing (slow) **)
   137 (** XML parsing (slow) **)
   132 
   138