Click here to Skip to main content
15,880,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have this piece of code below:
_____________________________________
C#
XmlDocument doc = new XmlDocument();
           string sFileName = @"C:\temp\testFile.xml";

           doc.Load(sFileName);

           XmlNodeList textNodes = doc.SelectNodes("//fbkMetaValueT");

           foreach (DataRow currentRow in ds.Tables[0].Rows)
           {
               string toTranslate = currentRow[3].ToString().Trim();

               for (int columnCounter = 4; columnCounter < ds.Tables[0].Columns.Count; columnCounter++)
               {
                   string countryCode = ds.Tables[0].Columns[columnCounter].ColumnName;
                   string translation = currentRow[columnCounter].ToString().Trim();

                   foreach (XmlNode currentNode in textNodes)
                   {
                       string longText = currentNode.Attributes[0].Value.Trim();
                       string locale = currentNode.Attributes[2].Value.Trim();

                       // strip out apostrophes
                       longText.Replace("'", "");
                       translation.Replace("'", "");
                       toTranslate.Replace("'", "");

                       if ((longText == toTranslate) && (locale == countryCode))
                       {
                           currentNode.Attributes[0].Value = translation;
                       }
                   }
               }
           }


           XmlWriterSettings settings = new XmlWriterSettings();
           settings.Encoding = Encoding.UTF8;
           settings.Indent = true;


           using (XmlWriter writer = XmlWriter.Create("c:\\temp\\test.xml",settings))
           {
               doc.WriteContentTo(writer);
               writer.Flush();
               writer.Close();
           }

________________________________________________
Esentially what I'm doing is scanning through a dataset and updating a Node Value within an existing XML file (which I've read in fine) - however I only want to update certain nodes where that node value matches a value in my dataset. This works fine - with all strings apart from those that contain an apostrophe character. The line that does the matching is:
if ((longText == toTranslate) && (locale == countryCode))
The longText string is compared to the toTranslate string. These are the two strings that contain the apostrophe characters. I know the value I want to update is also always located at [0] on the Attribute list
I've done some debugging and these values look exactly the same.
Can anyone help me on this? It's pretty urgent so any urgent help would be greatly appreciated
Many Thanks,
Dan
Posted
Updated 16-Sep-10 13:42pm
v3

The first line in your for loop sets countryCode to the ColumnName of the column from the database. Is that what you intended? it sounds a little odd to me, without having seen your data. :)
 
Share this answer
 
That is actually correct - each country has its own column of data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900