0

Получаю xml файл следующего содержания

string resp = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<response list=\"true\">\n <uid>182194</uid>\n <uid>2283152</uid>\n <uid>5637297</uid>....

Необходимо достать все uid использую следующий код на С#

XDocument doc = XDocument.Parse(resp);
var points = doc.Descendants("response");
foreach (XElement curent in points)
{
    string a = curent.Element("uid").Value;
    pad.WriteLine("id" + a);
}

Но удается достать всего один uid, после этого он выходи из цыкла.

1 ответ 1

1

var points = doc.Descendants("response");

этим действием вы получаете всего один элемент <response...> на что цикл закономерно выполняется всего один раз.

Решение достаточно простое:

XDocument doc = XDocument.Parse(resp);
var points = doc.Descendants("uid");
foreach (XElement curent in points)
{
    string a = curent.Value;
    Console.WriteLine("id" + a);
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.