Answer the question
In order to leave comments, you need to log in
C# XML file parsing
I have a file with content:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!-- API errors -->
<string name="705">Введите адрес эл. почты</string>
<string name="706">Неверно указан адрес эл. почты</string>
<string name="707">Введите пароль</string>
<string name="708">Неверно указан пароль</string>
</resources>
Answer the question
In order to leave comments, you need to log in
Add your own error handling.
using System;
using System.Linq;
using System.Xml.Linq;
namespace ConsoleApplication11
{
internal class Program
{
private static void Main(string[] args)
{
var xml = XDocument.Load("XMLFile1.xml");
Console.WriteLine(GetErrorText(706, xml));
Console.ReadLine();
}
private static string GetErrorText(int name, XDocument xDoc)
{
return xDoc.Root.Elements().First(el => int.Parse(el.Attribute("name").Value) == name).Value;
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question