Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file xmlParser.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185(*
* Xml Light, an small Xml parser/printer with DTD support.
* Copyright (C) 2003 Nicolas Cannasse (ncannasse@motion-twin.com)
* Copyright (C) 2003 Jacques Garrigue
*
* This library 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; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library has the special exception on linking described in file
* README.
*
* This library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*)openPrintfopenDtdopenTypestypet={mutableprove:bool;mutablecheck_eof:bool;mutableconcat_pcdata:bool;mutableresolve:(string->checked);}typesource=|SFileofstring|SChannelofin_channel|SStringofstring|SLexbufofLexing.lexbuftypestate={source:Lexing.lexbuf;stack:Xml_lexer.tokenStack.t;xparser:t;}exceptionInternal_erroroferror_msgexceptionNoMoreDataletxml_error=ref(fun_->assertfalse)letdtd_error=ref(fun_->assertfalse)letfile_not_found=ref(fun_->assertfalse)let_raisesefd=xml_error:=e;file_not_found:=f;dtd_error:=dletmake()={prove=true;check_eof=true;concat_pcdata=true;resolve=(funfile->raise(!file_not_foundfile))}letprovepv=p.prove<-vletresolvepf=p.resolve<-fletcheck_eofpv=p.check_eof<-vletconcat_pcdatapv=p.concat_pcdata<-vletpops=tryStack.pops.stackwithStack.Empty->Xml_lexer.tokens.sourceletpushts=Stack.pushts.stackletrecread_nodes=matchpopswith|Xml_lexer.PCDatas->PCDatas|Xml_lexer.Tag(tag,attr,true)->Element(tag,attr,[])|Xml_lexer.Tag(tag,attr,false)->Element(tag,attr,read_elems~tags)|t->pushts;raiseNoMoreDataandread_elems?tags=letelems=ref[]in(trywhiletruedomatchs.xparser.concat_pcdata,read_nodes,!elemswith|true,PCDatac,(PCDatac2)::q->elems:=PCData(sprintf"%s\n%s"c2c)::q|_,x,l->elems:=x::ldonewithNoMoreData->());matchpopswith|Xml_lexer.EndtagswhenSomes=tag->List.rev!elems|Xml_lexer.Eofwhentag=None->List.rev!elems|_t->matchtagwith|None->raise(Internal_errorEOFExpected)|Somes->raise(Internal_error(EndOfTagExpecteds))letread_xmls=matchs.xparser.prove,popswith|true,Xml_lexer.DocType(root,Xml_lexer.DTDFilefile)->letpos=Xml_lexer.poss.sourceinletdtd=s.xparser.resolvefileinXml_lexer.restorepos;letx=read_nodesinDtd.provedtdrootx|true,Xml_lexer.DocType(root,Xml_lexer.DTDDatadtd)->letdtd=Dtd.checkdtdinletx=read_nodesinDtd.provedtdrootx|false,Xml_lexer.DocType_->read_nodes|_,t->pushts;read_nodesletconvert=function|Xml_lexer.EUnterminatedComment->UnterminatedComment|Xml_lexer.EUnterminatedString->UnterminatedString|Xml_lexer.EIdentExpected->IdentExpected|Xml_lexer.ECloseExpected->CloseExpected|Xml_lexer.ENodeExpected->NodeExpected|Xml_lexer.EAttributeNameExpected->AttributeNameExpected|Xml_lexer.EAttributeValueExpected->AttributeValueExpected|Xml_lexer.EUnterminatedEntity->UnterminatedEntityletdtd_convert=function|Xml_lexer.EInvalidDTDDecl->InvalidDTDDecl|Xml_lexer.EInvalidDTDTag->InvalidDTDTag|Xml_lexer.EDTDItemExpected->DTDItemExpected|Xml_lexer.EInvalidDTDElement->InvalidDTDElement|Xml_lexer.EInvalidDTDAttribute->InvalidDTDAttributeletdo_parsexparsersource=tryXml_lexer.initsource;lets={source=source;xparser=xparser;stack=Stack.create();}inlettk=popsin(* skip UTF8 BOM *)iftk<>Xml_lexer.PCData"\239\187\191"thenpushtks;letx=read_xmlsinifxparser.check_eof&&pops<>Xml_lexer.Eofthenraise(Internal_errorEOFExpected);Xml_lexer.closesource;xwith|NoMoreData->Xml_lexer.closesource;raise(!xml_errorNodeExpectedsource)|Internal_errore->Xml_lexer.closesource;raise(!xml_erroresource)|Xml_lexer.Errore->Xml_lexer.closesource;raise(!xml_error(converte)source)|Xml_lexer.DTDErrore->Xml_lexer.closesource;raise(!dtd_error(dtd_converte)source)letparsep=function|SChannelch->do_parsep(Lexing.from_channelch)|SStringstr->do_parsep(Lexing.from_stringstr)|SLexbuflex->do_parseplex|SFilefname->letch=(tryopen_infnamewithSys_error_->raise(!file_not_foundfname))intryletx=do_parsep(Lexing.from_channelch)inclose_inch;xwithe->close_inch;raisee