def write_record(target, cr, count): 
	ckeys = cr.keys()
	for n in range(0, len(cr)): 
		kv = cr[ckeys[n]]
		if (type(kv) == list):
			target.write( utility.tabs(count) + utility.create_starting_xml_tag(ckeys[n]) + utility.get_newline() )
			if (ckeys[n] != "Goods") and (ckeys[n] != "Suggested_Actions"):
				for l in kv:
					write_record(target, l, count+1)
			if (ckeys[n] == "Goods"):
				for good in cr[ckeys[n]]:
					target.write( utility.tabs(count+1) + "<Good>" + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Good_Name"))
					target.write( good["Good_Name"])
					target.write( utility.create_closing_xml_tag("Good_Name") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Child_Labor") )
					target.write( good["Child_Labor"] )
					target.write( utility.create_closing_xml_tag("Child_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Forced_Labor") )
					target.write( good["Forced_Labor"]  )
					target.write( utility.create_closing_xml_tag("Forced_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+2) + utility.create_starting_xml_tag("Forced_Child_Labor")  )
					target.write( good["Forced_Child_Labor"]  )
					target.write( utility.create_closing_xml_tag("Forced_Child_Labor") + utility.get_newline() )
					target.write( utility.tabs(count+1) + "</Good>" + utility.get_newline() )
			if (ckeys[n] == "Suggested_Actions"):
				sga = cr[ckeys[n]]
				for action in sga:
					stripped = unicode(utility.unicode_to_str(action['Area']), 'ascii', 'ignore')
					xmltag = sanitize(utility.unicode_to_str(stripped))
					target.write( utility.tabs(count+1) + utility.create_starting_xml_tag(xmltag) + utility.get_newline() )
					for act in action['Actions']:
						target.write(utility.tabs(count+2) + utility.create_starting_xml_tag("Action") + utility.get_newline() )
						aname = special_chars.xml_safe(utility.unicode_to_str(act['Name']), sp_chars)
						ayears = special_chars.xml_safe(utility.unicode_to_str(act['Years']), sp_chars)
						target.write(utility.tabs(count+3) + utility.create_starting_xml_tag("Name")  
						             + aname + utility.create_closing_xml_tag("Name")
						             + utility.get_newline() )
						target.write(utility.tabs(count+3) + utility.create_starting_xml_tag("Years")  
						             + ayears + utility.create_closing_xml_tag("Years")
						             + utility.get_newline() )
						target.write(utility.tabs(count+2) + utility.create_closing_xml_tag("Action") + utility.get_newline() )
					target.write( utility.tabs(count+1) + utility.create_closing_xml_tag(xmltag) + utility.get_newline() )
			target.write( utility.tabs(count) + utility.create_closing_xml_tag(ckeys[n]) + utility.get_newline() )
		else:
			keyname = utility.to_str(ckeys[n])
			start = utility.create_starting_xml_tag(keyname)
			val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
			end = utility.create_closing_xml_tag(keyname)
			target.write( utility.tabs(count) + start + val + end + utility.get_newline() )
	return
def find_suggested_actions_section(country_record):
    count = -1
    sa_array = country_record['Sections']
    for section in sa_array:
        count += 1
        ctitle = utility.unicode_to_str(section['title'])
        if (suggested_actions_text in ctitle):
            break
        if (count == (len(sa_array) - 1)):
            count = -1

    return count
def find_suggested_actions_section(country_record):
    count = -1
    sa_array = country_record['Sections']
    for section in sa_array:
    	count += 1
    	ctitle = utility.unicode_to_str(section['title'])
    	if (suggested_actions_text in ctitle ):
    		break
    	if (count == (len(sa_array) - 1)):
    		count = -1

    return count
def write_record(target, cr, count):
    ckeys = cr.keys()
    for n in range(0, len(cr)):
        kv = cr[ckeys[n]]
        if (type(kv) == list):
            target.write(
                utility.tabs(count) +
                utility.create_starting_xml_tag(ckeys[n]) +
                utility.get_newline())
            if (ckeys[n] != "Goods") and (ckeys[n] != "Suggested_Actions"):
                for l in kv:
                    write_record(target, l, count + 1)
            if (ckeys[n] == "Goods"):
                for good in cr[ckeys[n]]:
                    target.write(
                        utility.tabs(count + 1) + "<Good>" +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Good_Name"))
                    target.write(good["Good_Name"])
                    target.write(
                        utility.create_closing_xml_tag("Good_Name") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Child_Labor"))
                    target.write(good["Child_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Child_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Forced_Labor"))
                    target.write(good["Forced_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Forced_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 2) +
                        utility.create_starting_xml_tag("Forced_Child_Labor"))
                    target.write(good["Forced_Child_Labor"])
                    target.write(
                        utility.create_closing_xml_tag("Forced_Child_Labor") +
                        utility.get_newline())
                    target.write(
                        utility.tabs(count + 1) + "</Good>" +
                        utility.get_newline())
            if (ckeys[n] == "Suggested_Actions"):
                sga = cr[ckeys[n]]
                for action in sga:
                    stripped = unicode(utility.unicode_to_str(action['Area']),
                                       'ascii', 'ignore')
                    xmltag = sanitize(utility.unicode_to_str(stripped))
                    target.write(
                        utility.tabs(count + 1) +
                        utility.create_starting_xml_tag(xmltag) +
                        utility.get_newline())
                    for act in action['Actions']:
                        target.write(
                            utility.tabs(count + 2) +
                            utility.create_starting_xml_tag("Action") +
                            utility.get_newline())
                        aname = special_chars.xml_safe(
                            utility.unicode_to_str(act['Name']), sp_chars)
                        ayears = special_chars.xml_safe(
                            utility.unicode_to_str(act['Years']), sp_chars)
                        target.write(
                            utility.tabs(count + 3) +
                            utility.create_starting_xml_tag("Name") + aname +
                            utility.create_closing_xml_tag("Name") +
                            utility.get_newline())
                        target.write(
                            utility.tabs(count + 3) +
                            utility.create_starting_xml_tag("Years") + ayears +
                            utility.create_closing_xml_tag("Years") +
                            utility.get_newline())
                        target.write(
                            utility.tabs(count + 2) +
                            utility.create_closing_xml_tag("Action") +
                            utility.get_newline())
                    target.write(
                        utility.tabs(count + 1) +
                        utility.create_closing_xml_tag(xmltag) +
                        utility.get_newline())
            target.write(
                utility.tabs(count) +
                utility.create_closing_xml_tag(ckeys[n]) +
                utility.get_newline())
        else:
            keyname = utility.to_str(ckeys[n])
            start = utility.create_starting_xml_tag(keyname)
            val = special_chars.xml_safe(utility.to_str(cr[keyname]), sp_chars)
            end = utility.create_closing_xml_tag(keyname)
            target.write(
                utility.tabs(count) + start + val + end +
                utility.get_newline())
    return