我创建了一个c#应用程序,我必须在其中加载.resx文件并在dgv上显示内容并加载.tmx文件并显示字符串的翻译。例如
<body>
<tu tuid="880">
<tuv xmllang="fr-FR">
<seg>Sélectionner un contact</seg>
</tuv>
<tuv xmllang="de-DE">
<seg>Kontakt auswählen</seg>
</tuv>
<tuv xmllang="en-US">
<seg>Choose Contact</seg>
</tuv>
<tuv xmllang="es-ES">
<seg>Elegir contacto</seg>
</tuv>
</tu>
我已经加载了dgv并在Source Column中显示了英文。如果dgv中的“Source”列包含“Choose Contact”,我必须在“Target”列中显示“Elegir contacto”。现在我使用了以下代码
XPathDocument doc;
XPathNavigator nav;
XPathExpression strExpression;
XPathNodeIterator iterator;
doc = new XPathDocument(OpenDialog.Filename);
nav = doc.CreateNavigator();
strExpression = "/body/tu[tuv/seg='Choose Contact']/tuv[@xmllang='fr-FR']/seg";
iterator = nav.Select(strExpression);
我被困在这条线之后。我必须在目标列中显示@xmllang值。我怎么能这样做?
答案 0 :(得分:0)
我不熟悉XPathDocument所以我为这种方法选择了XmlDocument
string givenString = "Choose Contact";
string language = "fr-FR";
XmlDocument doc = new XmlDocument();
string filePath = "sample.xml";
doc.Load(filePath);
string path = "//tuv[seg='" + givenString + "']";
XmlNode rootNode = doc.SelectSingleNode(path).ParentNode.Clone();
string childPath= "//tuv[@xmllang='" + language + "']";
XmlNode node = rootNode.SelectSingleNode(childPath);
Console.WriteLine(node.InnerText);
- SJ