Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read and Update xml file with Tranlsated language strings

Status
Not open for further replies.

vchinnikrishna

Programmer
Nov 11, 2011
1
US
Hi All,

I need to update the XML file with Translated string. I have one two dimensional array called XMLArray [,] and XML file.

If I found XMLArray[0,0] value in XML file, then need to replace XMLArray[0,1] value with it.

Please find the code below. At present my code is working fine, but when i upload huge file, its taking too much time. looping process is taking too much time. I am looking optimized code. if anyone resolve this issue it, will be the great.

string XMLArrayString="",XMLTString="";

for (int xmlLoop = 0; xmlLoop <= XMLLength - 1; xmlLoop++)

{

if (XMLArray[xmlLoop, 0] != null)

{

XMLArrayString = XMLArray[xmlLoop, 0].ToString();

XMLTString = XMLArray[xmlLoop, 1].ToString();

{

strExist = false;

intcount = 0;

foreach (XmlElement QPageEle in QPelements)

{

string strele = QPageEle.Name;

if (QPageEle.HasChildNodes)

{



for (int CNode = 0; CNode < QPageEle.ChildNodes.Count; CNode++)

{

if (QPageEle.ChildNodes[0].Name == "ComponentTitle")

{

XmlNodeList Qnode = QPageEle.ChildNodes[0].SelectNodes("//ComponentTitle/DisplayText/Localized/Content");

foreach (XmlElement qnod in Qnode)

{

string XMLString = qnod.InnerText.Trim();

if (XMLString == "How did this survey-taking experience compare to other online surveys you have taken?")

break;

if (XMLArrayString == XMLString)

{

qnod.InnerText = XMLTString == "" ? XMLArrayString : XMLTString;

strExist = true;

break;

}

}

}

if (QPageEle.ChildNodes.Count > 0)

{


 

if (QPageEle.ChildNodes[CNode].Name == "Answers" || QPageEle.ChildNodes[CNode].Name == "Prompts" || QPageEle.ChildNodes[CNode].Name == "Headings")

{

XmlNodeList Ansnodes1 = QPageEle.ChildNodes[CNode].SelectNodes("DisplayText/Localized/Content");


foreach (XmlElement anode in Ansnodes1)

{

string ansString = anode.InnerText.Trim();



if (ansString == XMLArrayString)

{

anode.InnerText = XMLTString == "" ? XMLArrayString : XMLTString;

strExist = true;

break;

}

}

}

}

}

}

intcount++;

if (strExist == true)

break;

}

}

}

}

XMLDoc.Save(strTXML);
 
to start I would replace the multidimensional array with XML objects. .Net has a number of components specifically designed to work with XML. depending on the size of the XML document an XmlDocument object may be all that's needed. you can then traverse the document using xPath queries and update the values accordingly.

if the files/strings are large, then you may want to switch over to an XmlReader and XmlWriter to prevent the entire document from being loaded into memory all at once.

you could even take advantage of linq2Xml to traverse the document. This is really just syntax sugar over xml reader/writer. it provides a more natural language to the code.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top