This one is pretty tricky because you have items that have items which probably could have items too... so if you do something like this.
Up vote 0 down vote favorite share g+ share fb share tw.
I'm having trouble parsing the following soap response. This is my first time working with LINQ and must examples I've found use XML and not a SOAP envelope. How do I get the values of the different "items".
I know there are different options (using add service reference) but it is not an option in my current project. Error OK Beatles 9 John Lennon 12 Paul McCartney 25 George Harrison 184 Ringo Starr Thanks in advance c# linq parsing soap link|improve this question edited Apr 17 '11 at 0:20Ivan Crojach Kara? I?779413 asked Apr 16 '11 at 22:42retain31.
This one is pretty tricky because you have items that have items which probably could have items too... so if you do something like this var returnResult = (from r in document. Descendants("item") select r).ToList(); you will get all the items separated and one which has all the values in one... edit: this works somewhat fine XDocument document = XDocument. Load(@"XMLFile1.
Xml"); List items = new List(); var returnResult = (from r in document. Descendants("item") select r).ToList(); foreach (XElement xElement in returnResult) { Item item = new Item(); item. Key = xElement.
Element("key")! = null? XElement.
Element("key"). Value : ""; item. Value = xElement.
Element("value")! = null? XElement.
Element("value"). Value : ""; items. Add(item); } //sort the list to get the one that have the rest to the end var sorted = (from s in items orderby s.Value.
Length ascending select s).ToList(); List finalList = new List(); items.Clear(); for (int I = 0; I sortedi.Value. Length) { Item itm = new Item(); itm. Key = sortedj.
Key; KeyValuePair kvp = new KeyValuePair(sortedi. Key,sortedi. Value); itm.Items.
Add(kvp); items. Add(itm); } else { if (!finalList. Contains(sortedi)) finalList.
Add(sortedi); } } } class Item { public List Items { get; set; } public string Key { get; set; } public string Value {get;set;} public Item() { Items = new List(); } } you can now see all sub items with their correct key... only the ok/error is making some trouble... but you can get them from the final list and pick them if they are not any of the key-value pairs... hope this helps.
Thanks a lot! , this does work but I find it weird how much complexity is brought on when having attributes with the same name inside other attributes... I guess the real solution would be to change the attributes name but I'm not involved with the development of the web service – retain Apr 17 '11 at 1:19 the problem is that you would probably be better of if it would be something like and ... then it would be pretty easy... because for each you know exactly which subelements belong to it and you wouldn't have to cheat :) – Ivan Crojach Kara? I?
Apr 17 '11 at 5:39.
You should be able to parse this by loading it into an XDocument. Then you can select out the values you require by specifying the element names. Finally you could return these values as a new anonymous type.
An example can be found in the response to this question: Using LINQ to XML to Parse a SOAP message Let me know if you have any problems.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.