--- loncom/xml/lonxml.pm 2010/02/11 20:44:15 1.494.4.4 +++ loncom/xml/lonxml.pm 2010/10/01 14:21:55 1.494.4.5 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.494.4.4 2010/02/11 20:44:15 raeburn Exp $ +# $Id: lonxml.pm,v 1.494.4.5 2010/10/01 14:21:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1523,17 +1523,25 @@ SIMPLECONTENT sub verify_html { my ($filecontents)=@_; - if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) { - return &mt('File does not have [_1] or [_2] starting tag','<html>','<xml>'); - } - if ($filecontents!~/(?:\<|\<\;)\/(?:html|xml)(?:\>|\>\;)/is) { - return &mt('File does not have [_1] or [_2] ending tag','<html>','<xml>'); - } - if ($filecontents!~/(?:\<|\<\;)(?:body|frameset)[^\<]*(?:\>|\>\;)/is) { - return &mt('File does not have [_1] or [_2] starting tag','<body>','<frameset>'); - } - if ($filecontents!~/(?:\<|\<\;)\/(?:body|frameset)[^\<]*(?:\>|\>\;)/is) { - return &mt('File does not have [_1] or [_2] ending tag','<body>','<frameset>'); + my ($is_html,$is_xml); + if ($filecontents =~/(?:\<|\<\;)\?xml[^\<]*\?(?:\>|\>\;)/is) { + $is_xml = 1; + } elsif ($filecontents =~/(?:\<|\<\;)html(?:\s+[^\<]+|\s*)(?:\>|\>\;)/is) { + $is_html = 1; + } + unless ($is_xml || $is_html) { + return &mt('File does not have [_1] or [_2] starting tag','<html>','<?xml ?>'); + } + if ($is_html) { + if ($filecontents!~/(?:\<|\<\;)\/html(?:\>|\>\;)/is) { + return &mt('File does not have [_1] ending tag','<html>'); + } + if ($filecontents!~/(?:\<|\<\;)(?:body|frameset)[^\<]*(?:\>|\>\;)/is) { + return &mt('File does not have [_1] or [_2] starting tag','<body>','<frameset>'); + } + if ($filecontents!~/(?:\<|\<\;)\/(?:body|frameset)[^\<]*(?:\>|\>\;)/is) { + return &mt('File does not have [_1] or [_2] ending tag','<body>','<frameset>'); + } } return ''; }