Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:51:37+00:00 2026-06-06T16:51:37+00:00

So I have a problem… I am trying to consolidate 5 or so bilingual

  • 0

So I have a problem… I am trying to consolidate 5 or so bilingual dictionaries, in HTML format, into a single, multilingual dictionary, with english as the source language. To do this, I decided to set up a dictionary, and map each non-english word to it’s english counterpart(key) [see code below].

1 public void ConsolidateDictionary(string directoryPath)
2 {
3    DirectoryInfo directory = new DirectoryInfo(directoryPath);
4    string key = string.Empty;
5    string value = string.Empty;
6    Dictionary<string, List<string>> languages = 
         new Dictionary<string, List<string>>();
7    List<string> temp = new List<string>();
8    foreach (FileInfo file in directory.EnumerateFiles())
9    {
10       HtmlDocument doc = new HtmlDocument();
11       doc.Load(file.FullName);
12
13       foreach (HtmlNode node in doc.DocumentNode.SelectNodes(".//wordunit"))
14       {
15          foreach (HtmlNode child in node.SelectNodes(".//word"))
16           {
17                   if (child.Attributes["language"].Value == "EN")
18                   {
19                       key = child.OuterHtml.ToString();
20                   }
21                   else
22                   {
23                       value = child.OuterHtml.ToString();
24                   }
25           }
26
27           if (key != null && value != null)
28           {
29               if (languages.ContainsKey(key))
30               {
31                   foreach (var item in languages[key])
32                   {
33                       temp.Add(item);
34                   }
35                   temp.Add(value);
36                   languages.Remove(key);
37                   languages.Add(key, temp);
38                   temp.Clear();
39               }
40               else
41               {
42                       temp.Add(value);
43                       languages.Add(key, temp);
44                       temp.Clear();
45               }
46           }
47       }
48   }
49   WriteFile(languages);
50 }

basically what is happening is, after each iteration of the foreach loop at line 15, the existing dictionary values are all nulled (but the keys remain). So, say that after the first iteration of the loop at line 15, the dictionary (called ‘languages’) contained: key: <word language="EN">Hello</word> Value: <word language="ES">Hola</word>; when the second iteration comes around, the value is removed from the dictionary ‘languages’, leaving only:

key: <word language="EN">Hello</word>
Value: null
key: <word language="EN">Goodbye</word>
Value: <word language="ES">Chao</word>

(where the Goodbye-Chao pair were passed in as the key-value pair for the second iteration).

What could be causing this strange behavior… to my knowledge I’m not overwriting the values in my dictionary at all! Does anyone have any idea where I’m going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:51:38+00:00Added an answer on June 6, 2026 at 4:51 pm
    temp.Add(value);
     //languages.Add(key, temp);
    temp.Clear();
    

    Look at what you’re doing to that poor List instance. Use a new List instance for each key.


    if (!languages.ContainsKey(key))
    {
      languages.Add(key, new List<string>())
    }
    languages[key].Add(value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem while loading data into html select when users press or click
I have problem adding markers into marker Clusterer of Google Maps. Firebug returns error:
I have problem in my PHP code. I'm trying to make internet shop and
I have problem with configuring NODE.JS. I was trying to install node.js with this
I have problem with Dictionary(buzzCompaignsPerUserIntersets) . I have dictionary (key = stringand value =
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start
I have problem with UIWebView delay when the load image from url. In my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.