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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:09:55+00:00 2026-06-12T11:09:55+00:00

How can I do a foreach where I can read just the XML tag

  • 0

How can I do a foreach where I can read just the XML tag Equipe where has the <DesFilialnet> equals Rest

This is an example:

<Equipe>
    <CPFUsuario>5546</CPFUsuario>
    <CodUsuario>6536</CodUsuario>
    <ApelidoUsuario>PARREIRA.MG</ApelidoUsuario>
    <NomeCompletoUsuario>JORGE</NomeCompletoUsuario>
    <CodAgenciaLopesnet>15513</CodAgenciaLopesnet>
    <DesAgenciaLopesnet>MINAS GERAIS LTDA.</DesAgenciaLopesnet>
    <DesFilialnet>Rest</DesFilialLopesnet>
    <CodEquipe>584309</CodEquipe>
    <CodEquipeNovo>597951</CodEquipeNovo>
    <DesEquipe>CARLOSMG</DesEquipe>
    <CodEquipeSecundaria />
    <CodEquipeSecundariaNovo />
    <DesEquipeSecundaria />
    <CodFilialSiebelPronto></CodFilialSiebelPronto>
    <GrupoAcesso>1</GrupoAcesso>
</Equipe>

I have a lot of Equipe tag, but the <DesFilialnet> change, and I want just the <Equipe> where <DesFilialnet> is Rest.

Follow how I’m doing

    public void leXmlCors(string file)
    {
        XmlReader rdr = XmlReader.Create(file);
        XDocument doc2 = XDocument.Load(rdr);

        foreach (var equipes in doc2.Root.Descendants("Equipe"))
        {
            foreach (var element in equipes.Descendants())
            {
                 // This will read all <Equipe> tag, but I don't want all <Equipe> tag
            }
        }
    }
}
  • 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-06-12T11:09:56+00:00Added an answer on June 12, 2026 at 11:09 am

    Give then XML:

    <Test>
        <Equipe>
            <CPFUsuario>5546</CPFUsuario>
            <CodUsuario>6536</CodUsuario>
            <ApelidoUsuario>PARREIRA.MG</ApelidoUsuario>
            <NomeCompletoUsuario>JORGE</NomeCompletoUsuario>
            <CodAgenciaLopesnet>15513</CodAgenciaLopesnet>
            <DesAgenciaLopesnet>MINAS GERAIS LTDA.</DesAgenciaLopesnet>
            <DesFilialnet>Rest</DesFilialnet>
            <CodEquipe>584309</CodEquipe>
            <CodEquipeNovo>597951</CodEquipeNovo>
            <DesEquipe>CARLOSMG</DesEquipe>
            <CodEquipeSecundaria />
            <CodEquipeSecundariaNovo />
            <DesEquipeSecundaria />
            <CodFilialSiebelPronto></CodFilialSiebelPronto>
            <GrupoAcesso>1</GrupoAcesso>
        </Equipe>
        <Equipe>
            <CPFUsuario>5546</CPFUsuario>
            <CodUsuario>6536</CodUsuario>
            <ApelidoUsuario>PARREIRA.MG</ApelidoUsuario>
            <NomeCompletoUsuario>JORGE</NomeCompletoUsuario>
            <CodAgenciaLopesnet>15513</CodAgenciaLopesnet>
            <DesAgenciaLopesnet>MINAS GERAIS LTDA.</DesAgenciaLopesnet>
            <DesFilialnet>not rest</DesFilialnet>
            <CodEquipe>584309</CodEquipe>
            <CodEquipeNovo>597951</CodEquipeNovo>
            <DesEquipe>CARLOSMG</DesEquipe>
            <CodEquipeSecundaria />
            <CodEquipeSecundariaNovo />
            <DesEquipeSecundaria />
            <CodFilialSiebelPronto></CodFilialSiebelPronto>
            <GrupoAcesso>1</GrupoAcesso>
        </Equipe>
    </Test>
    

    The following should work:

    var equipes = XDocument.Parse(xml)
                           .Elements("Test")
                           .Elements("Equipe")
                           .Where(e => e.Element("DesFilialnet")
                           .Value.ToUpperInvariant() == "Rest".ToUpperInvariant());
    

    You can now do your foreach loop on the resulting IEnumerable<XElement>:

    foreach (var xElement in equipes)
            {
               //Do something
            }
    

    Of course this will require Linq and the following using statements:

    using System.Xml.Linq;
    using System.Linq;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I sort this foreach loop with jQuery? I will sort on id
[1,2,3].forEach(function(el) { if(el === 1) break; }); How can I do this using the
I am just trying to read some details from an XML file, part of
I'm trying to read a XML file, but I want to know just the
I'm just learning PERL. I've read some docs on parsing XML and reused some
I found some example of how to read the XML from an Excel spreadsheet
I need to read an xml,I dont find another way to read it just
I need some help with LINQ and XML. I've read numerous articles but just
So I need an array from my data that I can foreach on the
In PHP, one can do foreach($array as $key=>$value){//codes . Is it possible to create

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.