diff --git a/gtkdoc-mkdb.in b/gtkdoc-mkdb.in
index 7592293..84a8b6e 100755
--- a/gtkdoc-mkdb.in
+++ b/gtkdoc-mkdb.in
@@ -258,9 +258,11 @@ my %AllDocumentedSymbols;
 # Undeclared yet documented symbols
 my %UndeclaredSymbols;
 
-# These global arrays store GObject, subclasses and the hierarchy.
+# These global arrays store GObject, subclasses and the hierarchy (also of
+# non-object derived types).
 my @Objects;
 my @ObjectLevels;
+my %ObjectRoots;
 
 my %Interfaces;
 my %Prerequisites;
@@ -2348,6 +2350,9 @@ sub OutputSGMLFile {
     my $object_anchors = "";
     foreach my $object (@$file_objects) {
         next if ($object eq $section_id);
+        next if ($ObjectRoots{$object} eq 'GEnum'
+                 or $ObjectRoots{$object} eq 'GFlags'
+                 or $ObjectRoots{$object} eq 'GBoxed');
         my $id = CreateValidSGMLID($object);
         #print "Debug: Adding anchor for $object\n";
         $object_anchors .= "<anchor id=\"$id\"$empty_element_end";
@@ -5149,12 +5154,17 @@ sub ReadObjectHierarchy {
     # child turns up.
     my @pending_objects = ();
     my @pending_levels = ();
+    my $root;
     while (<INPUT>) {
         if (m/\S+/) {
             my $object = $&;
             my $level = (length($`)) / 2 + 1;
             my $xref = "";
 
+            if ($level == 1) {
+                $root = $object;
+            }
+
             while (($#pending_levels >= 0) && ($pending_levels[$#pending_levels] >= $level)) {
                 my $pobject = pop(@pending_objects);
                 my $plevel = pop(@pending_levels);
@@ -5172,6 +5182,7 @@ sub ReadObjectHierarchy {
                      print (OUTPUT ' ' x ($level * 4), "$xref\n");
                     push (@Objects, $object);
                     push (@ObjectLevels, $level);
+                    $ObjectRoots{$object} = $root;
                 }
             }
             #else {
