[LON-CAPA-cvs] cvs: loncom /xml lonxml.pm

raeburn raeburn@source.lon-capa.org
Wed, 29 Sep 2010 15:53:07 -0000


raeburn		Wed Sep 29 15:53:07 2010 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
  Log:
  - Publication of files containing valid XML was being disallowed.
    - XML declaration is of the form: <?xml ?> (with no closing </xml> tag).
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.515 loncom/xml/lonxml.pm:1.516
--- loncom/xml/lonxml.pm:1.515	Wed Sep 29 15:47:21 2010
+++ loncom/xml/lonxml.pm	Wed Sep 29 15:53:07 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.515 2010/09/29 15:47:21 raeburn Exp $
+# $Id: lonxml.pm,v 1.516 2010/09/29 15:53:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1434,17 +1434,25 @@
 
 sub verify_html {
     my ($filecontents)=@_;
-    if ($filecontents!~/(?:\<|\&lt\;)(?:html|xml)[^\<]*(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] starting tag','&lt;html&gt;','&lt;xml&gt;');
-    }
-    if ($filecontents!~/(?:\<|\&lt\;)\/(?:html|xml)(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] ending tag','&lt;html&gt;','&lt;xml&gt;');
-    }
-    if ($filecontents!~/(?:\<|\&lt\;)(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] starting tag','&lt;body&gt;','&lt;frameset&gt;');
-    }
-    if ($filecontents!~/(?:\<|\&lt\;)\/(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] ending tag','&lt;body&gt;','&lt;frameset&gt;');
+    my ($is_html,$is_xml);
+    if ($filecontents =~/(?:\<|\&lt\;)\?xml[^\<]*\?(?:\>|\&gt\;)/is) {
+        $is_xml = 1;
+    } elsif ($filecontents =~/(?:\<|\&lt\;)html(?:\s+[^\<]+|\s*)[^\<]*(?:\>|\&gt\;)/is) {
+        $is_html = 1;
+    }
+    unless ($is_xml || $is_html) {
+        return &mt('File does not have [_1] or [_2] starting tag','&lt;html&gt;','&lt;?xml ?&gt;');
+    }
+    if ($is_html) {
+        if ($filecontents!~/(?:\<|\&lt\;)\/html(?:\>|\&gt\;)/is) {
+            return &mt('File does not have [_1] ending tag','&lt;html&gt;');
+        }
+        if ($filecontents!~/(?:\<|\&lt\;)(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
+            return &mt('File does not have [_1] or [_2] starting tag','&lt;body&gt;','&lt;frameset&gt;');
+        }
+        if ($filecontents!~/(?:\<|\&lt\;)\/(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
+            return &mt('File does not have [_1] or [_2] ending tag','&lt;body&gt;','&lt;frameset&gt;');
+        }
     }
     return '';
 }