|
hi
i implemented your first answer
i got an error at the line
label1.Text = Resource.MyLabelText;
i dont have any Resource or MyLabelText
what does it mean "Resource.MyLabelText;"
|
|
|
|
|
Add in your VS project a resource file, named it Resource.resx.
Then add an entry : "MyLabelText" value is BlaBlaBla
To add another resources, for example german, then do the same
again as above, change the filename to Resource.de.resx.
Then add an entry : "MyLabelText" value is BlaBlaBlaGerman
|
|
|
|
|
it means i have to maintian a Resource file for every language
and i have to do it manually
is there any another way that if we select a language then the label text should change to the selected language
|
|
|
|
|
|
No. Windows/dotNet can't automatically translate your application's text - you'll have to do that yourself (or get someone to do it for you)
|
|
|
|
|
vijaylumar wrote: is there any another way that if we select a language then the label text should change to the selected language
Windows can't automatically translate texts. You could use an online translation-service to do the translations, but those aren't nearly as accurate as you want them to be.
For inspiration on automated translations, start with this[^] CodeProject article.
I are Troll
|
|
|
|
|
Hi,
I have a set of mobile users, I need to simulate this MUs in the network, this MUs transfer data to each other, one MU can search for information from other MUs.
After that measure the response time when has result.
I don’t know how to set up.
I have ideas but I do not know how to set up
Thanks.
|
|
|
|
|
Hi,
Assuming I have an xml file which looks something like:
<main>
<field1>
<table>
<columns>
<column>
<ElementName>1234</ElementName>
<ElementValue>uyt</ElementValue>
</column>
...
</columns>
</table>
</field1>
...
<field2>
<table>
<columns>
<column>
<ElementName>654322</ElementName>
<ElementValue>xyz</ElementValue>
</column>
...
</columns>
</table>
...
</field2>
...
...
</main>
The code below retrieves the values for
ElementName>654322</ElementName> and
<ElementValue>xyz</ElementValue> as shown:
private void ModifyXML()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
// Retrieve all prices.
XmlNodeList nodeList = doc.GetElementsByTagName("ElementName");
foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "654322")
{
ListBox1.Items.Add(node.OuterXml);
ListBox1.Items.Add(node.NextSibling.OuterXml);
ListBox1.Items.Add("");
//Console.WriteLine(node.ChildNodes[0].Value);
//Console.WriteLine(node.NextSibling.InnerXml);
}
}
}
Question:
Please note that I do not want to use xpath or linq or database. Just the xmlDocument for business reasons
Using this code below, how can I add a column element i.e.
Thanks
<column>
<ElementName>newValue</ElementName>
<ElementValue>newdata</ElementValue>
</column>
OR
delete one of the above column elements i.e. to remove:
<column>
<ElementName>654322</ElementName>
<ElementValue>xyz</ElementValue>
</column>
|
|
|
|
|
Hi,
you could use the AppendChild and RemoveChild methods of the XmlNode-class. For this navigate to the node you want to remove and call
nodeToRemove.ParentNode.RemoveChild(nodeToRemove)
To add a new node call
node.AppendChild(newNode)
Have a look here for the full documentation
http://msdn.microsoft.com/en-us/library/system.xml.xmlnode_members.aspx[^]
Regards
Sebastian
|
|
|
|
|
Hi,
I have been looking at msdn samples.
It seems I am having problems with .Append
How do I append something like:
<column>
<ElementName>654322</ElementName>
<ElementValue>xyz</ElementValue>
</column>
|
|
|
|
|
You have to create a new node column. Then create nodes for elementname and elementvalue. Append these nodes to the column node. Last step is to append the column node to the node in your document.
Btw, if you want to create nodes, use the CreateNode method of your XmlDocument.
|
|
|
|
|
Not sure what you mean.
How is this possible to tell the system where exactly in the hierarchy to place this elelemnt within the file?
Are you able to write a test sample based on the xml I gave before?
Thanks
|
|
|
|
|
Well I will try (without intellisense)...
private void ModifyXML()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
XmlNodeList nodeList = doc.GetElementsByTagName("ElementName");
foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "654322")
{
ListBox1.Items.Add(node.OuterXml);
ListBox1.Items.Add(node.NextSibling.OuterXml);
ListBox1.Items.Add("");
XmlNode columnNode = doc.CreateElement("column");
XmlNode elementNameNode = doc.CreateElement("elementName");
XmlNode elementValueNode = doc.CreateElement("elementValue");
elementNameNode.InnerText = "foo";
elementValueNode.InnerText = "bar";
columnNode.AppendChild(elementNameNode);
columnNode.AppendChild(elementValueNode);
node.ParentNode.AppendChild(columnNode);
}
}
}
|
|
|
|
|
Hi,
I tried it with a bit of adjustments.
But I get this:
<column>
<ElementName>1234</ElementName>
<ElementValue>uyt</ElementValue>
<column>
<ElementName>newKey</ElementName>
<ElementValue>newValue</ElementValue>
</column>
</column>
instread of:
<column>
<ElementName>1234</ElementName>
<ElementValue>uyt</ElementValue>
<column>
<column>
<ElementName>newKey</ElementName>
<ElementValue>newValue</ElementValue>
</column>
-----------
This is the code:
Thanks
private void LoadXMLmodify()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
// Retrieve all prices.
XmlNodeList nodeList = doc.GetElementsByTagName("mapKey");
foreach (XmlNode node in nodeList)
{
string strValue = node.ChildNodes[0].Value.ToString();
if (strValue.ToLower() == "0024007")
{
if (node.NextSibling.InnerXml.Trim() == "1")
{
string strMapValue = node.NextSibling.InnerXml.Trim();
//Remove element...
//Debug.WriteLine("mapKey : " + strValue + " and mapValue : " + strMapValue + " removed.");
//node.RemoveChild(node.FirstChild);
//Add element...
XmlNode columnNode = doc.CreateElement("Mapping");
XmlNode elementKeyNode = doc.CreateElement("mapKey");
XmlNode elementValueNode = doc.CreateElement("mapValue");
elementKeyNode.InnerText = strValue;
elementValueNode.InnerText = "999";
columnNode.AppendChild(elementKeyNode);
columnNode.AppendChild(elementValueNode);
node.ParentNode.AppendChild(columnNode);
//string strMapValue = node.NextSibling.InnerText;
//Debug.WriteLine("mapValue changed from : " + strMapValue + " to : " + "newValue");
//node.NextSibling.InnerText = "newVlaue";
//doc.Save(strPath);
}
}
}
doc.Save(strPath);
}
|
|
|
|
|
okay, try node.parentnode.parentnode
You are appending the new column node to an existing column node, but it must be the node above the existing column node.
|
|
|
|
|
Error:
In my code I sent you it gives an error on the line:
foreach(XmlNode node in nodeList)
It says: The element list has changed. The enumeration operation failed to continue.
Thanks
|
|
|
|
|
As the error message is saying a list can not be changed during the iteration. Convert the XmlNodeList to an array and use this array to iterate through the nodes.
|
|
|
|
|
The xml has many many elements and subelements...
How can This be converted to array?
And may be I should not be in the loop to save?
Thanks
|
|
|
|
|
Build a new list or array containing the elements of the XmlNodeList.
List<XmlNode> myNodes = new List<XmlNode>(doc.GetElementsByTagName("ElementName"));
Then iterate through myNodes.
|
|
|
|
|
I guess I do not have to be in the loop when I add a new row?
Don't you think?
|
|
|
|
|
Yes that is correct. But sometimes the logic just needs to be done within a loop. If you can avoid doing all this within the loop -> do it.
|
|
|
|
|
I have modified the loop so that as soon as there is an addition to the xml, then save the file and then break; this way it comes out of the loop.
Question:
I can see the xml I added is in there, so I now try to remove it as follows:
Do you see what is wrong here because i get an error on line with ????? it says object reference not set to an instance of an object.
Not that this error does not always happen. It seems I have to close the file and then re-open it to work correctly. Is this the way it should be?
Thanks
private void LoadXMLRemove()
{
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
// Retrieve all .
XmlNodeList nodeList = doc.GetElementsByTagName("mapKey");
foreach (XmlNode node in nodeList)
{
//?????
string strValue = node.ChildNodes[0].Value.ToString();
//???????
if (strValue.ToLower() == "0024007")
{
if (node.NextSibling.InnerXml.Trim() == "1")
{
string strMapValue = node.NextSibling.InnerXml.Trim();
//Remove element...
Debug.WriteLine("mapKey : " + strValue + " and mapValue : " + strMapValue + " removed.");
node.RemoveChild(node.FirstChild);
doc.Save(strPath);
break;
}
}
}
}
modified on Tuesday, October 13, 2009 8:05 AM
|
|
|
|
|
It seems that the node you doesn't have a childnode. Did you try to debug?
|
|
|
|
|
this error does not always happen. It seems I have to close the file and then re-open it to work correctly. Is this the way it should be?
Thanks
|
|
|
|
|
hi,
This list requires int
How is this code corrected please?
Thanks
|
|
|
|