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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:35:13+00:00 2026-06-17T07:35:13+00:00

I have an XML file as you can see below. I want to create

  • 0

I have an XML file as you can see below. I want to create another XML file using this XML file but the new XML file can only have those tags which have values. For example – in the below XML file I have an employee Sam who does not have city and state so my new XML file must not contain these empty tags. I am new to LINQ to XML but my friend said that I can achieve it using LINQ to XML. Any help will be greatly appreciated.

Thanks.

   <?xml version="1.0" encoding="utf-8" ?>
        <Employees>
         <Employee>
<EmpId>1</EmpId>
<Name>Sam</Name>   
<Sex>Male</Sex>
<Phone Type="Home">423-555-0124</Phone>
<Phone Type="Work">424-555-0545</Phone>
          <Address>
  <Street>7A Cox Street</Street>
  <City></City>
  <State></State>
  <Zip>95220</Zip>
  <Country>USA</Country>
</Address>
      </Employee>
             <Employee>
<EmpId>2</EmpId>
<Name>Lucy</Name>
<Sex>Female</Sex>
<Phone Type="Home">143-555-0763</Phone>
<Phone Type="Work">434-555-0567</Phone>
<Address>
  <Street>Jess Bay</Street>
  <City>Alta</City>
  <State>CA</State>
  <Zip>95701</Zip>
  <Country>USA</Country>
</Address>
  </Employee>
       <Employee>
<EmpId>3</EmpId>
<Name>Kate</Name>
<Sex>Female</Sex>
<Phone Type="Home">166-555-0231</Phone>
<Phone Type="Work">233-555-0442</Phone>
<Address>
  <Street>23 Boxen Street</Street>
  <City>Milford</City>
  <State>CA</State>
  <Zip>96121</Zip>
  <Country>USA</Country>
</Address>
     </Employee>
           <Employee>
<EmpId>4</EmpId>
<Name>Chris</Name>
<Sex>Male</Sex>
<Phone Type="Home">564-555-0122</Phone>
<Phone Type="Work">442-555-0154</Phone>
<Address>
  <Street>124 Kutbay</Street>
  <City>Montara</City>
  <State>CA</State>
  <Zip>94037</Zip>
  <Country>USA</Country>
</Address>

  • 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-17T07:35:15+00:00Added an answer on June 17, 2026 at 7:35 am
    XDocument xdoc = XDocument.Load(path_to_xml);
    xdoc.Descendants("Employee")
        .Where(e => e.Descendants().Any(d => String.IsNullOrEmpty(d.Value)))
        .Remove();
    xdoc.Save(path_to_xml);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file (see below) and can display all the Product Names
I have created XML file,but I can't view it/output it.I know there is no
I have generated an excel file from xml. But i can not open it
I have XML (see below). I need to insert the records in this XML
I have a .xml file in my App_Data folder, I can access it fine
What are DataContracts in WCF ? I have an XML file , how can
I have to encrypt/decrypt some sensitive information in a Xml file? Yes I can
I have custom component that I can place in my layout file (XML) for
I want to save data from a xml file to my database, and below
I have the below JSON (been snipped for space), as you can see in

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.