This code works as intended, however, I am sure that there is a way to condense the xmldataLoad
method. If someone could maybe explain a better approach than what I have done with the method, I would be extremely grateful.
Essentially, what I am saying is I am rather new to using LINQ and don't fully understand the various ways of using it, and I am quite sure there are many people in the same boat as I am.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Xml.Serialization;
//using XMLControlLibrary;
namespace EJCTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void xmlDataLoad()
{
string xmlPath = @"C:\Users\Jesse\Source\Repos\AsyncSpeechSynth\EJCTest\XMLControlLibrary\newDictionary.xml";
XDocument xdoc = XDocument.Load(xmlPath);
var eng = from wordList in xdoc.Root.Elements("Word")
select wordList.Element("English").Value;
engList.ItemsSource = eng.ToList();
var rom = from wordList in xdoc.Root.Elements("Word")
select wordList.Element("Romaji").Value;
romList.ItemsSource = rom.ToList();
var jpn = from wordList in xdoc.Root.Elements("Word")
select wordList.Element("Japanese").Value;
jpnList.ItemsSource = jpn.ToList();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
xmlDataLoad();
}
public class WordList
{
string english;
string romaji;
string japanese;
public string English
{
get { return english; }
set { english = value; }
}
public string Romaji
{
get { return romaji; }
set { romaji = value; }
}
public string Japanese
{
get { return japanese; }
set { japanese = value; }
}
}
}
}
using
a lot. I can't imagine you need all of those. \$\endgroup\$