Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file xml_iter.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163(* TyXML
* http://www.ocsigen.org/tyxml
* Copyright (C) 2004 Thorsten Ohl <ohl@physik.uni-wuerzburg.de>
* Copyright (C) 2011 Pierre Chambart, Grégoire Henry
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02111-1307, USA.
*)moduleMake(Xml:Xml_sigs.Iterable)=structopenXml(** Iterators *)letamap1fn=matchcontentnwith|Empty|Comment_|PCDATA_|EncodedPCDATA_|Entity_->n|Leaf(name,attribs)->leaf~a:(fnameattribs)name|Node(name,attribs,elts)->node~a:(fnameattribs)nameeltsletrecamapfn=matchcontentnwith|Empty|Comment_|PCDATA_|EncodedPCDATA_|Entity_->n|Leaf(name,attribs)->leaf~a:(fnameattribs)name|Node(name,attribs,elts)->node~a:(fnameattribs)name(List.map(amapf)elts)letrecadd_float_attribnamevalue=function|[]->[float_attribnamevalue]|head::tailwhenanamehead=name->float_attribnamevalue::tail|head::tail->head::add_float_attribnamevaluetailletmap_float_attribis_attribfl=letauxhead=matchacontentheadwith|AFloatvaluewhenis_attrib(anamehead)->float_attrib(anamehead)(fvalue)|_->headinList.mapauxlletrecadd_int_attribnamevalue=function|[]->[int_attribnamevalue]|head::tailwhenanamehead=name->int_attribnamevalue::tail|head::tail->head::add_int_attribnamevaluetailletrecrm_attribis_attrib=function|[]->[]|head::tailwhenis_attrib(anamehead)->rm_attribis_attribtail|head::tail->head::rm_attribis_attribtailletmap_int_attribis_attribfl=letauxhead=matchacontentheadwith|AIntvaluewhenis_attrib(anamehead)->int_attrib(anamehead)(fvalue)|_->headinList.mapauxlletrecadd_string_attribnamevalue=function|[]->[string_attribnamevalue]|head::tailwhenanamehead=name->string_attribnamevalue::tail|head::tail->head::add_string_attribnamevaluetailletmap_string_attribis_attribfl=letauxhead=matchacontentheadwith|AStrvaluewhenis_attrib(anamehead)->string_attrib(anamehead)(fvalue)|_->headinList.mapauxlletrecadd_space_sep_attribnamevalue=function|[]->[space_sep_attribname[value]]|head::tail->matchacontentheadwith|AStrL(Space,values')whenanamehead=name->space_sep_attribname(value::values')::tail|_whenanamehead=name->space_sep_attribname[value]::tail|_->head::add_space_sep_attribnamevaluetailletrecadd_comma_sep_attribnamevalue=function|[]->[comma_sep_attribname[value]]|head::tail->matchacontentheadwith|AStrL(Comma,values')whenanamehead=name->comma_sep_attribname(value::values')::tail|_whenanamehead=name->comma_sep_attribname[value]::tail|_->head::add_comma_sep_attribnamevaluetailletrecrm_attrib_from_listis_attribis_value=function|[]->[]|head::tail->matchacontentheadwith|AStrL(sep,values)whenis_attrib(anamehead)->beginmatchList.filter(funv->not(is_valuev))valueswith|[]->tail|values'->matchsepwith|Space->space_sep_attrib(anamehead)values'::tail|Comma->comma_sep_attrib(anamehead)values'::tailend|_->head::rm_attrib_from_listis_attribis_valuetailletmap_string_attrib_in_listis_attribfl=letauxhead=matchacontentheadwith|AStrL(sep,values)whenis_attrib(anamehead)->beginmatchsepwith|Comma->comma_sep_attrib(anamehead)(List.mapfvalues)|Space->space_sep_attrib(anamehead)(List.mapfvalues)end|_->headinList.mapauxlletrecfoldof_emptyof_commentof_txtof_encodedpcdataof_entityof_leafof_noden=matchcontentnwith|Empty->of_empty()|Comments->of_comments|PCDATAs->of_txts|EncodedPCDATAs->of_encodedpcdatas|Entitys->of_entitys|Leaf(name,attribs)->of_leafnameattribs|Node(name,attribs,elts)->of_nodenameattribs(List.map(foldof_emptyof_commentof_txtof_encodedpcdataof_entityof_leafof_node)elts)letall_entitieselt=letf_=[]infoldfffff(fun_ename_attribs->[])(fun_ename_attribselts->List.flattenelts)eltletflatmapfl=List.concat(List.mapfl)lettranslateroot_leafroot_nodesub_leafsub_nodeupdate_statestaten=letrectranslate'staten=matchcontentnwith|(Empty|Comment_|PCDATA_|EncodedPCDATA_|Entity_)->[n]|Leaf(name,attribs)->sub_leafstatenameattribs|Node(name,attribs,elts)->sub_nodestatenameattribs(flatmap(translate'(update_statenameattribsstate))elts)inmatchcontentnwith|(Empty|Comment_|PCDATA_|EncodedPCDATA_|Entity_)->n|Leaf(name,attribs)->root_leafnameattribs|Node(name,attribs,elts)->root_nodenameattribs(flatmap(translate'state)elts)end