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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:58:50+00:00 2026-05-22T16:58:50+00:00

I would like to select all elements of a var q = from artikel

  • 0

I would like to select all elements of a

var q = from artikel in xmlSource.Descendants("ART")
    where artikel.Element("ID").Value.Equals("15")
    select artikel.Elements();

 //Does not work
 foreach (var element in q)
 {
    Console.WriteLine("Customer name = {0}", element.Name);
 }

How can I output all elements? I have some problems with iterators.

I don’t now how to iterate a
IEnumerable
with foreach and access the element.Name property.

//*** Aditional Information //

Example XML

<ARTICLE>
  <ART>
    <ID>0020209</ID>
    <EXP>36</EXP>
    <QTY>1</QTY>
    <SMCAT>B</SMCAT>
    <DSCRD>Example Description 1</DSCRD>
    <ARTCOMP>
      <COMPNO>10710</COMPNO>
      <ROLE>H</ROLE>
      <ARTNO1>320059</ARTNO1>
      <ARTNO2>320059</ARTNO2>
    </ARTCOMP>
    <ARTCOMP>
      <COMPNO>10710</COMPNO>
      <ROLE>V</ROLE>
      <ARTNO1>320059</ARTNO1>
      <ARTNO2>320059</ARTNO2>
    </ARTCOMP>
    <ARTBAR>
      <CDTYP>E13</CDTYP>
      <BC>7680202580475</BC>
      <BCSTAT>A</BCSTAT>
    </ARTBAR>
    <ARTPRI>
      <VDAT>2010-12-01T00:00:00+01:00</VDAT>
      <PTYP>PEXF</PTYP>
      <PRICE>30</PRICE>
    </ARTPRI>
  </ART>
  <ART>
    <ID>0020244</ID>
    <EXP>60</EXP>
    <QTY>30</QTY>
    <DSCRD>FERRO GRADUMET Depottabl 30 Stk</DSCRD>
    <ARTCOMP>
      <COMPNO>1836</COMPNO>
      <ROLE>H</ROLE>
      <ARTNO1>685230</ARTNO1>
      <ARTNO2>685230</ARTNO2>
    </ARTCOMP>
    <ARTCOMP>
      <COMPNO>1836</COMPNO>
      <ROLE>V</ROLE>
      <ARTNO1>685230</ARTNO1>
      <ARTNO2>685230</ARTNO2>
    </ARTCOMP>
    <ARTCOMP>
      <COMPNO>5360</COMPNO>
      <ROLE>L</ROLE>
      <ARTNO1>685230</ARTNO1>
      <ARTNO2>685230</ARTNO2>
    </ARTCOMP>
  </ART>
</ARTICLE>

I have to import this XML File into a normalized MySQL Table. ARTCOMP / ARTBAR are additional tables in the MySQL Datebase.

As a beginning, I wanted to create all the fields as varchar() in an empty MySQL Table. As an additional problem, not every ART element has the same child elements. Maybe there is a better way of finding all possible child elements (kind of schema).

  • 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-22T16:58:50+00:00Added an answer on May 22, 2026 at 4:58 pm

    Your select clause means that the type of q is actually IEnumerable<IEnumerable<XElement>>. I suspect you mean:

    var q = from artikel in xmlSource.Descendants("ART")
            where artikel.Element("ID").Value.Equals("15")
            from element in artikel.Elements()
            select element;
    

    Or:

    var q = from artikel in xmlSource.Descendants("ART")
            where (string) artikel.Element("ID") == "15"
            from element in artikel.Elements()
            select element;
    

    or even:

    var q = from artikel in xmlSource.Descendants("ART")
            where (int) artikel.Element("ID") == 15
            from element in artikel.Elements()
            select element;
    

    That will give a type for q of just IEnumerable<XElement> – it will flatten the results, basically. You’ll get a sequence of all elements which are directly beneath an element called “ART” which in turn has an “ID” element of with a value of 15.

    If that’s not what you’re looking for, please give more information – ideally a sample XML file along with your expected output.

    It seems unlikely that you really want to print the element name of all the elements though… the customer name should be stored as a value somewhere (either text within the element or an attribute), not as the element name.

    EDIT: If you want to use an IEnumerable<IEnumerable<XElement>> you can use:

    foreach (var result in q)
    {
        Console.WriteLine("Next result...");
        foreach (var element in result)
        {
            Console.WriteLine("Got name: {0}", element.Name);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to select all elements that have certain attribute or don't have
I would like to select all matches from a commaseparated column in table2, where
I would like to select all elements, for example a tags $('a').blabla(); But I
I have a pretty specific scenario where I would like to select all elements
I would like to delete all the rows found by that query: SELECT cart_abandon.*
I would like to run something like: select * from table where field in
I would like to select a row from the database based on two input
I would like to select a set of elements that are both of a
I would like to select all jquery UI button that live inside all <div>
I would like to have jQuery append a style=text-align: left; to all elements on

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.