validator/httpd/cgi-bin check,1.488,1.489

Update of /sources/public/validator/httpd/cgi-bin
In directory hutz:/tmp/cvs-serv27048

Modified Files:
	check 
Log Message:
routine to check presence and value of xmlns attribute, generally necessary for conformance, but not well expressed in DTD

Index: check
===================================================================
RCS file: /sources/public/validator/httpd/cgi-bin/check,v
retrieving revision 1.488
retrieving revision 1.489
diff -u -d -r1.488 -r1.489
--- check	28 Mar 2007 02:34:04 -0000	1.488
+++ check	28 Mar 2007 05:51:14 -0000	1.489
@@ -2177,6 +2177,63 @@
     $self->{am_in_heading} = 1;
   }
   
+  if (($element->{Name} eq 'html') and ($self->{_file}->{Mode} eq 'XML')){
+    # we check if xmlns has been properly given
+    my $has_xmlns = FALSE;
+    my $xmlns_value = undef;
+    foreach my $attr (keys %{$element->{Attributes}}) {
+      if ($element->{Attributes}->{$attr}->{Name} eq "xmlns") {
+        # Try with SAX method
+        if($element->{Attributes}->{$attr}->{Value} ){
+          $has_xmlns = TRUE;
+          $xmlns_value = $element->{Attributes}->{$attr}->{Value}; 
+        }
+        #next if ($has_xmlns);
+        
+        # the following is not SAX, but OPENSP specific
+
+        if ( $element->{Attributes}->{$attr}->{Defaulted}){
+          
+          if ($element->{Attributes}->{$attr}->{Defaulted} eq "specified") {
+            $has_xmlns = TRUE;
+            foreach my $datachunk (@{$element->{Attributes}->{$attr}->{CdataChunks}}) {
+              $xmlns_value = $xmlns_value.$datachunk->{Data};
+            }
+          }
+        }
+        
+      }
+    }
+    if ($has_xmlns == FALSE){
+      my $err;
+      my $location = $self->{_parser}->get_location();
+      $err->{src}  = '...'; # do this with show_open_entities()?
+      $err->{line} = $location->{LineNumber};
+      $err->{char} = $location->{ColumnNumber};
+      $err->{num}  = "no-xmlns";
+      $err->{type} = "E";
+      $err->{msg}  = "Missing xmlns attribute for element ".$element->{Name};
+
+      # ...
+      $self->{_file}->{'Is Valid'} = FALSE;
+      push @{$self->{_file}->{Errors}}, $err;
+    }
+    elsif (($has_xmlns == TRUE) and ($xmlns_value ne $CFG->{Types}->{$self->{_file}->{DOCTYPE}}->{Namespace}) ) {
+      my $err;
+
+      $err->{src}  = '...'; # do this with show_open_entities()?
+      $err->{line} = $element->{Location};
+      $err->{char} = $element->{Location};
+      $err->{num}  = "wrong-xmlns";
+      $err->{type} = "E";
+      $err->{msg}  = "Wrong xmlns attribute for element ".$element->{Name}.". Value should be". $CFG->{Types}->{$self->{_file}->{DOCTYPE}}->{Namespace};
+
+      # ...
+      $self->{_file}->{'Is Valid'} = FALSE;
+      push @{$self->{_file}->{Errors}}, $err;
+
+    }
+  }
 }
 
 

Received on Wednesday, 28 March 2007 05:51:19 UTC