C# 从xml中获取单词的所有定义

C# 从xml中获取单词的所有定义,c#,xml,wpf,C#,Xml,Wpf,我有以下XML <entry_list version="1.0"> <entry id="sweet tooth"> <ew>sweet tooth</ew> <hw>sweet tooth</hw> <fl>noun</fl> <def> <date>14th century</date> <dt>:a craving

我有以下XML

<entry_list version="1.0">
<entry id="sweet tooth">
  <ew>sweet tooth</ew>
  <hw>sweet tooth</hw>
  <fl>noun</fl>
  <def>
    <date>14th century</date>
    <dt>:a craving or fondness for sweet food</dt>
  </def>
</entry>
</entry_list>

甜食
甜食
名词
十四世纪
:对甜食的渴望或喜爱
我怎么才能只表现出“对甜食的渴望或喜爱”这一部分呢?XML放在一个文本框中,但我希望文本框只显示渴望行

此外,如果我搜索一些不太具体的东西,比如“计算机”,有很多定义。如何选择最早的定义?这是用于计算机的XML

   <entry_list version="1.0">
  <entry id="computer">
    <ew>computer</ew>
    <subj>CP#IS</subj>
    <hw>com*put*er</hw>
    <sound>
      <wav>comput06.wav</wav>
      <wpr>kum-!pyU-tur</wpr>
    </sound>
    <pr>kノ冦-ヒ・yテシ-tノ决</pr>
    <fl>noun</fl>
    <lb>often attributive</lb>
    <def>
      <date>1646</date>
      <dt>:one that <fw>computes</fw></dt>
      <sd>specifically</sd>
      <dt>:a programmable usually electronic device that can store, retrieve, and process data</dt>
    </def>
    <uro>
      <ure>com*put*er*dom</ure>
      <sound>
        <wav>comput07.wav</wav>
        <wpr>kum-!pyU-tur-dum</wpr>
      </sound>
      <pr>-dノ冦</pr>
      <fl>noun</fl>
    </uro>
    <uro>
      <ure>com*put*er*less</ure>
      <sound>
        <wav>comput08.wav</wav>
        <wpr>kum-!pyU-tur-lus</wpr>
      </sound>
      <pr>-lノ冱</pr>
      <fl>adjective</fl>
    </uro>
    <uro>
      <ure>com*put*er*like</ure>
      <sound>
        <wav>comput09.wav</wav>
        <wpr>kum-!pyU-tur-+lIk</wpr>
      </sound>
      <pr>-ヒ畦トォk</pr>
      <fl>adjective</fl>
    </uro>
  </entry>
  <entry id="computer science">
    <ew>computer science</ew>
    <subj>CP</subj>
    <hw>computer science</hw>
    <fl>noun</fl>
    <def>
      <date>1961</date>
      <dt>:a branch of science that deals with the theory of computation or the design of computers</dt>
    </def>
  </entry>
  <entry id="analog computer">
    <ew>analog computer</ew>
    <subj>CP</subj>
    <hw>analog computer</hw>
    <fl>noun</fl>
    <def>
      <date>1948</date>
      <dt>:a computer that operates with numbers represented by directly measurable quantities (as voltages or rotations) <dx>compare <dxt>digital computer</dxt><dxt>hybrid computer</dxt></dx></dt>
    </def>
  </entry>
  <entry id="digital computer">
    <ew>digital computer</ew>
    <subj>CP</subj>
    <hw>digital computer</hw>
    <fl>noun</fl>
    <def>
      <date>1947</date>
      <dt>:a computer that operates with numbers expressed directly as digits <dx>compare <dxt>analog computer</dxt><dxt>hybrid computer</dxt></dx></dt>
    </def>
  </entry>
  <entry id="home computer">
    <ew>home computer</ew>
    <subj>CP</subj>
    <hw>home computer</hw>
    <fl>noun</fl>
    <def>
      <date>1976</date>
      <dt>:a personal computer used in the home</dt>
    </def>
  </entry>
  <entry id="hybrid computer">
    <ew>hybrid computer</ew>
    <subj>CP</subj>
    <hw>hybrid computer</hw>
    <fl>noun</fl>
    <def>
      <date>1968</date>
      <dt>:a computer system consisting of a combination of analog and digital computer systems</dt>
    </def>
  </entry>
  <entry id="personal computer">
    <ew>personal computer</ew>
    <subj>CP</subj>
    <hw>personal computer</hw>
    <fl>noun</fl>
    <def>
      <date>1976</date>
      <dt>:a general-purpose computer equipped with a microprocessor and designed to run especially commercial software (as a word processor or Internet browser) for an individual user</dt>
    </def>
  </entry>
</entry_list>

计算机
CP是
com*put*er
comput06.wav
库姆!琵琶
Kノ冦-ヒ・Yテシ-Tノ决
名词
经常定语
1646
:计算的人
明确地
:一种可编程的电子设备,通常可以存储、检索和处理数据
com*put*er*dom
comput07.wav
库姆!九土墩
-dノ冦
名词
com*put*er*less
comput08.wav
库姆!卑土鲁
-lノ冱
形容词
com*put*er*like
comput09.wav
库姆!pyU tur-+lIk
-ヒ畦トォK
形容词
计算机科学
人物配对关系
计算机科学
名词
1961
:研究计算理论或计算机设计的科学分支
模拟计算机
人物配对关系
模拟计算机
名词
1948
:一种计算机,使用直接可测量的量(如电压或旋转)表示的数字进行操作,比较数字计算机混合计算机
数字计算机
人物配对关系
数字计算机
名词
1947
:用数字直接表示的计算机。比较模拟计算机混合计算机
家用电脑
人物配对关系
家用电脑
名词
1976
:家庭中使用的个人电脑
混合计算机
人物配对关系
混合计算机
名词
1968
:由模拟和数字计算机系统组合而成的计算机系统
个人电脑
人物配对关系
个人电脑
名词
1976
:一种装有微处理器的通用计算机,专门为个人用户运行商业软件(如文字处理器或互联网浏览器)
一步一步地

  • 首先编写一个c#应用程序来读取xml怎么样
  • 选择所需的xml标记
  • 把它展示出来
  • 以C#读取xml可在(流方式)中找到 对于小xml,更喜欢DOM(一次读入),这样就有点简单了:

    选择xml标记,在第一种情况下可以是for循环中的switch语句;或者就像在DOM中选择节点和属性一样简单

    在WPF中显示,应该是最简单的。只需将此值传递给WPF

    希望有帮助


    我应该在上面写评论,但随着公司合并、域名变更,我的电子邮件地址丢失了。我没有足够的理由写评论。所以把答案放在这里。希望可以帮助您,也可以帮助我建立积分。

    尝试以下xml linq:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            const string FILENAME = @"c:\temp\test.xml";
            static void Main(string[] args)
            {
                XDocument doc = XDocument.Load(FILENAME);
    
                string word = "computer";
    
                List<XElement> computers = doc.Descendants("entry").Where(x => (string)x.Attribute("id") == word).ToList();
    
                var definitions = computers.Select(x => new {
                    word = (string)x.Attribute("id"),
                    definitions = x.Elements("def").Select(y => new {
                        dts = y.Elements("dt").Select(z => (string)z).ToList()
                    }).FirstOrDefault()
                }).ToList();
            }
        }
    }
    
    使用系统;
    使用System.Collections.Generic;
    使用System.Linq;
    使用系统文本;
    使用System.Xml;
    使用System.Xml.Linq;
    命名空间控制台应用程序1
    {
    班级计划
    {
    常量字符串文件名=@“c:\temp\test.xml”;
    静态void Main(字符串[]参数)
    {
    XDocument doc=XDocument.Load(文件名);
    string word=“计算机”;
    列表计算机=文档子体(“条目”)。其中(x=>(字符串)x.Attribute(“id”)==word.ToList();
    变量定义=计算机。选择(x=>new{
    word=(字符串)x.Attribute(“id”),
    定义=x.Elements(“def”)。选择(y=>new{
    dts=y.Elements(“dt”).Select(z=>(string)z.ToList()
    }).FirstOrDefault()
    }).ToList();
    }
    }
    }