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 120589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:50:07+00:00 2026-05-11T03:50:07+00:00

We utilise a third party web service that returns XML which looks something like

  • 0

We utilise a third party web service that returns XML which looks something like (cut down for brevity):

<Response>   <block name='availability'>     <block name='cqual'>       <a name='result-code' format='text'>L</a>     </block>     <block name='exchange'>       <a name='code' format='text'>MRDEN</a>     </block>     <block name='mqual'>       <a name='rate-adaptive' format='text'>G</a>     </block>   </block>   <block name='products'>     <block>       <a name='product-id' format='counting'>1235</a>       <block name='realms'>         <block>           <a name='realm' format='text'>-u@surfuk1</a>         </block>       </block>     </block>     <block>       <a name='product-id' format='counting'>1236</a>       <block name='realms'>         <block>           <a name='realm' format='text'>-u@surfuk2</a>         </block>       </block>     </block>     <block>       <a name='product-id' format='counting'>1237</a>       <block name='realms'>         <block>           <a name='realm' format='text'>-u@surfuk3</a>         </block>       </block>     </block>   </block>   <status no='0' /> </Response> 

For a specific product code I need to obtain the realm name i.e. the inner text of:

<a name='realm' format='text'>-u@surfuk2</a>

Because every element name is either <block> or <a> it’s a bit troublesome to parse with linq to xml or query expressions.

Is the following the most effective/efficient/expressive way to get at the realm name for a specific product, e.g. 1235:

List<XElement> products = response     .Element('Response')     .Elements('block')     .Where(x => x.Attribute('name').Value == 'products')     .Elements('block').ToList(); // // I broke down the query to aid readability // string realm = products.Elements('a')     .Where(x => x.Attribute('name').Value == 'product-id')     .Where(y => y.Value == '1235') // hardcoded for example use     .Ancestors()     .First()     .Elements('block')     .Where(z => z.Attribute('name').Value == 'realms')     .Elements('block')     .Elements('a')     .First().Value; 
  • 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. 2026-05-11T03:50:08+00:00Added an answer on May 11, 2026 at 3:50 am

    The definition of realm as provided is the equivalent of the simpler:

    string realm = (string) products.XPathEvaluate(    'string(       /*/blocks[@name='products']                  /*/a[@name='product-id' and . = '1236']                               /following-sibling::block[1]           )    '                                      ) 

    This in fact is both more readable and more compact than the definition of realm provided in the original question.

    As efficiency is concerned, it could well be that evaluating a single XPath expression may turn out to be more efficient, too, however to find if this is true we need to write an application that will compare the timings of the two methods.

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

Sidebar

Related Questions

I've built web apps before that utilize phpBB session, and user data. The common
I have built ASP.NET app. I need to utilize a third party COM object
I have a problem using a third-party component in Delphi 2006 (also Delphi 7),
Is there a way to utilise the GCC compiler whilst still being able to
Is there any easy way to explicitly make an already threaded application utilise a
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
I'd like to utilize an ICE Faces fileInput control to fill in the file
I would like to utilize the ASP.NET AJAX Page Methods functionality with a user
Or any open source project which utilize collective intelligence extensively?.
I'm working on a project with a friend that will utilize Hbase to store

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.