Codebase list ohcount / 85d5c3b4-c1f3-4d55-a24f-4c231b8d4c21/main ruby / gestalt / rules / csproj_parser.rb
85d5c3b4-c1f3-4d55-a24f-4c231b8d4c21/main

Tree @85d5c3b4-c1f3-4d55-a24f-4c231b8d4c21/main (Download .tar.gz)

csproj_parser.rb @85d5c3b4-c1f3-4d55-a24f-4c231b8d4c21/mainraw · history · blame

#!/usr/bin/env ruby
require 'rexml/document'
require 'rexml/streamlistener'

class CsprojListener
	include REXML::StreamListener

	attr_accessor :callback
	def initialize(callback)
		@callback = callback
		@is_csproj_file = false
	end

	def tag_start(name, attrs)
		case name
		when 'Project'
			@is_csproj_file = true
			if attrs['xmlns'] and attrs['xmlns'] !~ /^http:\/\/schemas\.microsoft\.com\/developer\//
				# False alarm -- it contains a project element, but of another namespace
				@is_csproj_file = false
			end
		when 'Import'
			if @is_csproj_file && attrs['Project']
				@callback.call(attrs['Project'])
			end
		end
	end
end