def analyze_document(doc)
     # Add a namespace declaration for XPath expressions
     doc.root.namespaces.default_prefix = 'db'
     # Analyze the document starting with the root node
     doc_maps = check_node(doc.root,0,[])
     @sections = []
     section_name = doc_maps[0][:title]
     section_type = doc_maps[0][:name]
     section_ctr = 0
     section_level = 0
     max_section_level = 0
     doc_ctr = 0
     xms = doc_maps.drop(1)
     # Compute word counts per section
     xms.each do |m|
       if (m[:type] == :para)
         doc_ctr += m[:words]
         section_ctr += m[:words]
       else
         @sections << {:title => section_name, :words => section_ctr, :level => section_level, :tag => section_type}
         section_name = m[:title]
         section_ctr = 0
         section_level = m[:level]
         max_section_level = m[:level] if (m[:level] > max_section_level)
         section_type = m[:name]
       end
     end
     @sections << {:title => section_name, :words => section_ctr, :level => section_level, :tag => section_type}
     # OPTIMIZE Not nice, but works
     @sections = sum_sections(@sections,max_section_level).map {|s|
       s[:words] = s[:words]+s[:swords];
       s.delete(:swords)
       s
     }
     @sections
   end
def analyze_document(doc)
     # Add a namespace declaration for XPath expressions
     doc.root.namespaces.default_prefix = 'db'
     # Analyze the document starting with the root node
     doc_maps = check_node(doc.root,0,[])
     @sections = []
     section_name = doc_maps[0][:title]
     section_type = doc_maps[0][:name]
     section_ctr = 0
     section_level = 0
     max_section_level = 0
     doc_ctr = 0
     xms = doc_maps.drop(1)
     # Compute word counts per section
     xms.each do |m|
       if (m[:type] == :para)
         doc_ctr += m[:words]
         section_ctr += m[:words]
       else
         @sections << {:title => section_name, :words => section_ctr, :level => section_level, :tag => section_type}
         section_name = m[:title]
         section_ctr = 0
         section_level = m[:level]
         max_section_level = m[:level] if (m[:level] > max_section_level)
         section_type = m[:name]
       end
     end
     @sections << {:title => section_name, :words => section_ctr, :level => section_level, :tag => section_type}
     # OPTIMIZE Not nice, but works
     @sections = sum_sections(@sections,max_section_level).map {|s|
       s[:words] = s[:words]+s[:swords];
       s.delete(:swords)
       s
     }
     @sections
   end
Searches the XML document for sections and word counts. Returns an
 array of sections (map) with title, word count, section level and DocBook tag.