我想在c#中获得word的同义词。例如,merhaba - hello或selam-hi。我只能对"hello“执行"merhaba”,但不能访问其他节点。(merhaba-hi或selam-hi)我该怎么做?谢谢。
我的XML文件。
<Words>
<Meaning>
<Turkish type="noun">merhaba</Turkish>
<Turkish type="noun">selam</Turkish>
<English type="noun">hello</English>
<English type="noun">hi</English>
</Meaning>
</Words>我的查询是这样的。
var word = from p in doc.Elements("Words").Elements("Meaning")
where textBox1.Text == p.Element("Turkish").Value
select new
{
_word = p.Element("Turkish").Value,
meaning = p.Element("English").Value,
kind = p.Element("English").Attribute("type").Value
};发布于 2012-07-23 18:40:54
你可能会想要尝试这样的东西:
var word = from p in doc.Elements("Words").Elements("Meaning")
where p.Elements("Turkish").Any(item => item.Value == textBox1.Text)
from synonym in p.Elements("English")
select new
{
_word = textBox1.Text,
meaning = synonym.Value,
kind = synonym.Attribute("type").Value
};表达式p.Elements("Turkish").Any(item => item.Value == textBox1.Text)查找包含所需单词的含义元素。from synonym in p.Elements("English")行遍历所有名为English的元素。
https://stackoverflow.com/questions/11609050
复制相似问题