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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:52:40+00:00 2026-05-17T20:52:40+00:00

I need to get data from a XML file from Node1>Node2 Filter data to

  • 0

I need to get data from a XML file from Node1>Node2

Filter data to group from the xml by X Node where X node is equals A,Y,Z..

Group all elements with same X Node value ordered by date

Store first element of the group(as ordered by date would be by the latest), and the rest in a subgroup of the same object.

If in the filter fails to find one Node equals(A,X or Z) then it creates an first element with hardcoded data for the fist element.

Once this process is finish then send the object (list<>) to a repeater.

I have nearly everything but I don’t know how to do it for when the filter fails to find a Node that is equals to (A,X or Z)

Code Example.

   private void BindOutputRepeaterLongTermCondition()
                {

          XDocument xd = XDocument.Parse(element.OuterXml);

                if (xd != null)
                {

                    var results = (from el1 in xd.Descendants("Node1")
                                   from el2 in el1.Descendants("Node2")
                                   where el2.Element("Date") != null    
                               &&(el2.Element("Code").Value.StartsWith("A") 
                                   || el2.Element("Code").Value.StartsWith("Y")
                                   || el2.Element("Code").Value.StartsWith("Z")
                                   || el2.Element("Code").Value.StartsWith("B")
                                   )
                                   orderby el2.Element("Date").Value descending
                                   group el2 by el2.Element("Code").Value
                                       into CodeGroup
                                       select new Table(CodeGroup.First())
                                       {
                                           SubTable = (from subCodes in CodeGroup
                                                           select new Table(subCodes)).Skip(1).ToList()
                                       }).ToList<Table>();




                     this.repeaterTable.DataSource = results;
                     this.repeaterTable.DataBind();


                }

            }



            protected void repeater_Table_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
            {
                RepeaterItem item = e.Item;
                if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
                {
                    var recentTable = (Table)item.DataItem;
                    var TableRepeater = (Repeater)item.FindControl("rptSubTable");
                    TableRepeater.DataSource = recentTable.SubTable;
                    TableRepeater.DataBind();
                }
            }


        }

        public class Table
        {
            public string Date { get; set; }
            public string Rubric { get; set; }
            public string Value { get; set; }
            public List<Table> SubTable { get; set; }



            public Table(XElement xml)
            {


                Date = xml.Element("Date") != null ? xml.Element("Date").Value : "";
                Code = xml.Element("Code") != null ? xml.Element("Code").Value : "";

                var a = (string)xml.Element("Code").Value;

                if (a.StartsWith("A"))
                {
                    Name = "Row 1";
                }
                else if (a.StartsWith("Y"))
                {
                    Name = "Row 2";
                }
                else if (a.StartsWith("Z"))
                {
                    Name = "Row 3";
                }

                else if (a.StartsWith("B"))
                {
                    Name = "Row 4";
                }

//Tried the following but it does not work.
                else if (!a.StartsWith("A") && !a.StartsWith("Y") && !a.StartsWith("B")){
                 Name = "Row 3";
                 Value = "Not Found";
                 }
              }

        }

XML Code example

<Node1>
    <Node2>
        <Date>2009-07-16</Date>
        <Code>A</Code>
        <Value>Some Value</Value>
    </Node2>
    <Node2>
        <Date>2008-02-09</Date>
        <Code>Y</Code>
        <Value>Some Value</Value>
    </Node2>
    <Node2>
        <Date>2008-02-09</Date>
        <Code>Z</Code>
        <Value>Some Value</Value>           
    </Node2>
    <Node2>
        <Date>2008-07-16</Date>
        <Code>A</Code>
        <Value>Some Value</Value>
    </Node2>
    <Node2>
        <Date>2006-02-09</Date>
        <Code>Y</Code>
        <Value>Some Value</Value>
    </Node2>
    <Node2>
        <Date>2001-02-09</Date>
        <Code>Z</Code>
        <Value>Some Value</Value>           
    </Node2>
 </Node1>

Any help would be appreciated.

Update
The problem is that I need to display all elements whether they are on the xml or not.
At the moment I can only display existing elements.
If one of the elements (by “Code”) is not found I need to display hardcoded name of the element and value “No 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. Editorial Team
    Editorial Team
    2026-05-17T20:52:41+00:00Added an answer on May 17, 2026 at 8:52 pm

    Instead of the final elseif:

    else if (!a.StartsWith("A") && !a.StartsWith("Y") && !a.StartsWith("B")){
                     Name = "Row 3";
                     Value = "Not Found";
                     }
    

    Have you tried

    else
    {
    Name = "Row n";
    Value = "Not Found";
    }
    

    It should just fall through to that branch if all other conditions are not met (unless I am missing something)

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

Sidebar

Related Questions

I need to get data from an XML file and store it into a
I need to make a nodes tree from data.xml file (as here link text
I need to figure out how to get the data from D3D textures and
I've got a simple POCO class to hold data extracted from an XML file
I am using XmlReader.Create to retrieve data from an RSS xml file. Then I
New to jQuery, I have a script that returns data from an XML file.
I need to write model data ( CharField s only) to an XML file
We need to get data out of an older accounting system. We have received
I often have data in Excel or text that I need to get into
We have this set of data that we need to get the average of

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.