@davron2813

Как мне распарсить xml данные такого типа в C#?

Привет как мне распарсить данные которые я получаю от soap сервера в C#?
вот xml
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:countriesListResponse>
<return xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">1</key>
<value xsi:type="xsd:string">test1</value>
</item>
<item>
<key xsi:type="xsd:string">4</key>
<value xsi:type="xsd:string">test5</value>
</item>
</return>
</ns1:countriesListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
  • Вопрос задан
  • 739 просмотров
Решения вопроса 1
@bmforce
XDocument doc = XDocument.Parse(xmlString);
            IEnumerable<XElement> elements = doc.Descendants("item");

            foreach (var item in elements)
            {
                Console.WriteLine(item.Element("key").Value + " " + item.Element("value").Value);
            }
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы