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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:12:32+00:00 2026-05-27T21:12:32+00:00

<root> <data1> <Element1>Value</Element1> <Element2>Value</Element2> <Element3>Value</Element3> </data1> <data2> <Element1>Value</Element1> <Element2>Value</Element2> </data2> </root> From the above

  • 0
<root>
    <data1>
        <Element1>Value</Element1>
        <Element2>Value</Element2>
        <Element3>Value</Element3>
    </data1>
    <data2>
        <Element1>Value</Element1>
        <Element2>Value</Element2>
    </data2>
</root>

From the above XML I would like to make an XML looking like this:

<root>
    <d1e1>value<d1e1>
    <d1e2>value<d1e2>
    <d2e1>value<d2e1>
</root>

What is the most efficient way to process that?
Foreach or Linq in theory Linq should be faster in most cases and speed is of the essence for this project

Any idea?

  • 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-27T21:12:32+00:00Added an answer on May 27, 2026 at 9:12 pm

    The idea was to just select X nodes out of a pool of Y and the example here is simplified to show you the problem. In general it is like that I have a multi level xml that I needed to flat out to only have one sublevel (aka root + level1) but from the source I only need to have certain elements that are of interest to me.

    Anyway the issiue is solved cos I done it with foreach cos I found out that if you have an shema specified in the xml but not accessable LINQ dosent whant to work anyway.

    the solution was like this:

    1. I made a function:

      public System.Xml.XmlElement GetSubElement(XmlElement Parent, string element)
      {
       System.Xml.XmlElement ret = null;
       if (Parent == null)
        return ret;
      
       XmlNodeList ContentNodes = Parent.GetElementsByTagName(element);
       if (ContentNodes.Count > 0)
       {
        XmlNode node = ContentNodes.Item(0);
        ret = (XmlElement)node;
       }
      
       return ret;
      }
      
    2. I made a foreach loop on the area that was repeating

    3. I got the elements that where out of the repeating context with the above function.

    Anyway that solved it for me.

    Edit:
    Don’t know how to get this code to appear properly cos Ctrl+K dosent seem to do it

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

Sidebar

Related Questions

SELECT * FROM emp FOR XML AUTO , ROOT ('Employees') , ELEMENTS this query
I have this XML: <root> <data name=lnkViewResultResource1.Text xml:space=preserve> <value>bekijk de resultaten</value> </data> <data name=lnkVoteResource1.Text
I have xml what il get from third party application and structure looks like
Greetings! If I have XML such as this: <Root> <AlphaSection> . . . </AlphaSection>
Given this XML data: <root> <item>apple</item> <item>orange</item> <item>banana</item> </root> I can use this XSLT
I am getting this error: Data at the root level is invalid. Line 1,
root@everton-laptop:/opt/tinyos-1.x/apps/Blink# make pc compiling Blink to a pc binary ncc -o build/pc/main.exe -g -O0
This is link to the root of my question: JQuery UI Multiselect how to
<root> <data name=ID1></data> <data name=ID2></data> </root> XDocument xmlDoc = XDocument.Load(xmlFile); bool exists = (from
Here is the XML outline: <Root> <Thing att=11> <Child lang=e> <record></record> <record></record> <record></record> </Child

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.