split1.cd 872 Bytes
Newer Older
1
type Person = FPerson | MPerson
2
type FPerson = <person gender="F" >[ Name Children ]
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
type MPerson = <person gender="M">[ Name Children ]
type Children = <children>[Person*]
type Name = <name>[ PCDATA ]

type Man = <man name=String>[ Sons Daughters ]
type Woman = <woman name=String>[ Sons Daughters ]
type Sons = <sons>[ Man* ]
type Daughters = <daughters>[ Woman* ]

let split (MPerson -> Man ; FPerson -> Woman)
 <person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*] ] ->
   let tag = match g with "F" -> `woman | "M" -> `man in
   let s = map mc with x -> split x in
   let d = map fc with x -> split x in       
   <(tag) name=n>[ <sons>s  <daughters>d ] 

19
match argv [] with
20 21 22 23 24
  | [ f ] -> 
   (match load_xml f with
    |  <doc>(l & [Person*]) -> <doc>(map l with x -> split x)
    | _ -> raise "Invalid document") 
  | _ -> raise "Invalid command line"