Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4541190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:11:43+00:00 2026-05-21T15:11:43+00:00

I’m having trouble parsing the following soap response. This is my first time working

  • 0

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.

<SOAP-ENV:Envelope 
xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" 
xmlns:ns1=\"http://random.com/api/1/service\" 
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:getBeatlesResponse>
           <return xsi:type=\"ns2:Map\">
               <item>
                   <key xsi:type=\"xsd:string\">error</key>
                   <value xsi:type=\"xsd:string\">OK</value>
               </item>
               <item>
                   <key xsi:type=\"xsd:string\">Beatles</key>
                   <value xsi:type=\"ns2:Map\">
                       <item>
                           <key xsi:type=\"xsd:int\">9</key>
                           <value xsi:type=\"xsd:string\">John Lennon</value>
                       </item>
                       <item>
                           <key xsi:type=\"xsd:int\">12</key>
                           <value xsi:type=\"xsd:string\">Paul McCartney</value>
                       </item>
                       <item>
                           <key xsi:type=\"xsd:int\">25</key>
                           <value xsi:type=\"xsd:string\">George Harrison</value>
                       </item>
                       <item>
                           <key xsi:type=\"xsd:int\">184</key>
                           <value xsi:type=\"xsd:string\">Ringo Starr</value>
                       </item>
                   </value>
               </item>
           </return>
       </ns1:getBeatlesResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:11:44+00:00Added an answer on May 21, 2026 at 3:11 pm

    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<Item> items = new List<Item>();
    
            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<Item> finalList = new List<Item>();
    
            items.Clear();
            for (int i = 0; i < sorted.Count - 1; i++)
            {
                for (int j = 1; j < sorted.Count; j++)
                {
                    if (sorted[j].Value.Contains(sorted[i].Value) &&
                        sorted[j].Value.Length > sorted[i].Value.Length)
                    {
                        Item itm = new Item();
                        itm.Key = sorted[j].Key;
                        KeyValuePair<string, string> kvp = new KeyValuePair<string, string>(sorted[i].Key,sorted[i].Value);
                        itm.Items.Add(kvp);
                        items.Add(itm);
    
                    }
                    else
                    {
                        if (!finalList.Contains(sorted[i]))
                            finalList.Add(sorted[i]);
                    }
                }
            }
    class Item
    {
        public List<Item> Items { get; set; }
        public string Key { get; set; }
        public string Value {get;set;}
        public Item()
        {
            Items = new List<Item>();
        }
    }
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.