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

  • Home
  • SEARCH
  • 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 121959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:03:11+00:00 2026-05-11T04:03:11+00:00

I’m currently working on a Silverlight app and need to convert XML data into

  • 0

I’m currently working on a Silverlight app and need to convert XML data into appropriate objects to data bind to. The basic class definition for this discussion is:

public class TabularEntry     {         public string Tag { get; set; }         public string Description { get; set; }         public string Code { get; set; }         public string UseNote { get; set; }         public List<string> Excludes { get; set; }         public List<string> Includes { get; set; }         public List<string> Synonyms { get; set; }         public string Flags { get; set; }         public List<TabularEntry> SubEntries { get; set; }     } 

An example of the XML that might come in to feed this object follows:

<I4 Ref='1'>222.2     <DX>Prostate</DX>     <EX>         <I>adenomatous hyperplasia of prostate (600.20-600.21)</I>         <I>prostatic:             <I>adenoma (600.20-600.21)</I>             <I>enlargement (600.00-600.01)</I>             <I>hypertrophy (600.00-600.01)</I>         </I>     </EX>     <FL>M</FL> </I4> 

So, various nodes map to specific properties. The key ones for this question are the <EX> and <I> nodes. The <EX> nodes will contain a collection of one or more <I> nodes and in this example matches up to the ‘Excludes’ property in the above class definition.

Here comes the challenge (for me). I don’t have control over the web service that emits this XML, so changing it isn’t an option. You’ll notice that in this example one <I> node also contains another collection of one or more <I> nodes. I’m hoping that I could use a LINQ to XML query that will allow me to consolidate both levels into a single collection and will use a character that will delimit the lower level items, so in this example, when the LINQ query returned a TablularEntry object, it would contain a collection of Exclude items that would appear as follows:

  • adenomatous hyperplasia of prostate (600.20-600.21)
  • prostatic:
  • *adenoma (600.20-600.21)
  • *enlargement (600.00-600.01)
  • *hypertrophy (600.00-600.01)

So, in the XML the last 3 entries are actually child objects of the second entry, but in the object’s Excludes property, they are all part of the same collection, with the former child objects containing an identifier character/string.

I have the beginnings of the LINQ query I’m using below, I can’t quite figure out the bit that will consolidate the child objects for me. The code as it exists right now is:

List<TabularEntry> GetTabularEntries(XElement source)         {             List<TabularEntry> result;              result = (from tabularentry in source.Elements()                          select new TabularEntry()                          {                              Tag = tabularentry.Name.ToString(),                              Description = tabularentry.Element('DX').ToString(),                              Code = tabularentry.FirstNode.ToString(),                              UseNote = tabularentry.Element('UN') == null ? null : tabularentry.Element('UN').Value,                              Excludes = (from i in tabularentry.Element('EX').Elements('I')                                              select i.Value).ToList()                          }).ToList();              return result;         } 

I’m thinking that I need to nest a FROM statement inside the

Excludes = (from i…)

statement to gather up the child nodes, but can’t quite work it through. Of course, that may be because I’m off in the weeds a bit on my logic.

If you need more info to answer, feel free to ask.

Thanks in advance,

Steve

  • 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-11T04:03:11+00:00Added an answer on May 11, 2026 at 4:03 am

    Try this:

        List<TabularEntry> GetTabularEntries(XElement source)     {         List<TabularEntry> result;          result = (from tabularentry in source.Elements()                   select new TabularEntry()                   {                       Tag = tabularentry.Name.ToString(),                       Description = tabularentry.Element('DX').ToString(),                       Code = tabularentry.FirstNode.ToString(),                       UseNote = tabularentry.Element('UN') == null ? null : tabularentry.Element('UN').Value,                       Excludes = (from i in tabularentry.Element('EX').Descendants('I')                                   select (i.Parent.Name == 'I' ? '*' + i.Value : i.Value)).ToList()                    }).ToList();          return result;     } 

    (edit)

    If you need the current nested level of ‘I’ you could do something like:

        List<TabularEntry> GetTabularEntries(XElement source)     {         List<TabularEntry> result;          result = (from tabularentry in source.Elements()                   select new TabularEntry()                   {                       Tag = tabularentry.Name.ToString(),                       Description = tabularentry.Element('DX').ToString(),                       Code = tabularentry.FirstNode.ToString(),                       UseNote = tabularentry.Element('UN') == null ? null : tabularentry.Element('UN').Value,                       Excludes = (from i in tabularentry.Element('EX').Descendants('I')                                   select (ElementWithPrefix(i, '*'))).ToList()                    }).ToList();          return result;     }      string ElementWithPrefix(XElement element, char c)     {         string prefix = '';         for (XElement e = element.Parent; e.Name == 'I'; e = e.Parent)         {             prefix += c;         }         return prefix + ExtractTextValue(element);     }      string ExtractTextValue(XElement element)     {         if (element.HasElements)         {             return element.Value.Split(new[] { '\n' })[0].Trim();         }         else             return element.Value.Trim();     } 

    Input:

    <EX>     <I>adenomatous hyperplasia of prostate (600.20-600.21)</I>     <I>prostatic:         <I>adenoma (600.20-600.21)</I>         <I>enlargement (600.00-600.01)</I>         <I>hypertrophy (600.00-600.01)             <I>Bla1</I>             <I>Bla2                 <I>BlaBla1</I>             </I>             <I>Bla3</I>         </I>             </I> </EX> 

    Result:

    * adenomatous hyperplasia of prostate (600.20-600.21) * prostatic: * *adenoma (600.20-600.21) * *enlargement (600.00-600.01) * *hypertrophy (600.00-600.01) * **Bla1 * **Bla2 * ***BlaBla1 * **Bla3 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We're currently using Lucene.Net 2.0.0.4 in our beta release as… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer Jon, One of the first things to understand is that… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer Why ping Google? The only server you really care about… May 11, 2026 at 6:00 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.