XDocument doc = XDocument.Load("test.xml");
if (doc != null)
{
XNamespace ns0 = XNamespace.Get("namespace2");
var errorList = doc.Descendants(ns0 + "ResultHeader")
.Select(d => new {
Id = d.Element(ns0 + "Id").Value,
Info = d.Element(ns0 + "Info").Value
});
Console.WriteLine("Count: {0}", errorList.Count());
foreach (var error in errorList)
{
Console.WriteLine("{0}", error.Id);
Console.WriteLine("{0}", error.Info);
}
}
Sekmes
k.
"Jonas" <jonas.zajanckauskas@gmail.com> wrote in message
news:icm4ve$2ct$1@trimpas.omnitel.net...
> Sveiki, reikia is xml'o nuskaityti reiksmes ir biski jame pasiklydau :)
> nesu stiprus nei xml'e nei linq, taigi uzvedimas ant kelio labai apgelbetu
> :)
>
> Turiu tokios strukturos xml'a:
> <soapenv:Envelope
> xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <NS1:getErrorsResponse xmlns:NS1="namespace1">
> <ns0:Result xmlns:ns0="namespace2">
> <ns0:ResultHeader>
> <ns0:Id>0</ns0:Id>
> <ns0:Info>na</ns0:Info>
>
>
> Bandau Id ir Info reiksmiu lista istraukti taip:
>
> XDocument doc = XDocument.Load(tr);
> XNamespace ns0 = "namespace2";
> //XNamespace ns1 = "namespace1";
>
>
> var errorIrasai = from errprIrasas in doc.Descendants(ns0 +
> "ResultHeader")
> select new FErrors
> {
> Id = errprIrasas.Element(ns0 +
> "Id").Value,
> Info = errprIrasas.Element(ns0 +
> "Info").Value
> };
>
>
> Ir man errorIrasai.Count() grazina 0... Kaip suprantu gaunu 0 irasu nes
> pirma reikia pasiekti vidines sakas iki namespace2? Kaip tia gal42iau
> padaryti?