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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:19:30+00:00 2026-06-13T06:19:30+00:00

I have this XML file: <MyXml> <MandatoryElement1>value</MandatoryElement1> <MandatoryElement2>value</MandatoryElement2> <MandatoryElement3>value</MandatoryElement3> <CustomElement1>value</CustomElement1> <CustomElement2>value</CustomElement2> <MyXml> All 3

  • 0

I have this XML file:

<MyXml>
    <MandatoryElement1>value</MandatoryElement1>
    <MandatoryElement2>value</MandatoryElement2>
    <MandatoryElement3>value</MandatoryElement3>
    <CustomElement1>value</CustomElement1>
    <CustomElement2>value</CustomElement2>
<MyXml>

All 3 elements that are called ‘MandatoryElementX’ will always appear in the file. The elements called ‘CustomElementX’ are unknown. These can be added or removed freely by a user and have any name.

What I need is to fetch all the elements that are not MandatoryElements. So for the file above I would want this result:

<CustomElement1>value</CustomElement1>
<CustomElement2>value</CustomElement2>

I don’t know what the names of the custom elements may be, only the names of the 3 MandatoryElements, so the query needs to somehow exclude these 3.

Edit:
Even though this was answered, I want to clarify the question. Here is an actual file:

<Partner>
    <!--Mandatory elements-->
    <Name>ALU FAT</Name>
    <InterfaceName>Account Lookup</InterfaceName>
    <RequestFolder>C:\Documents and Settings\user1\Desktop\Requests\ALURequests</RequestFolder>
    <ResponseFolder>C:\Documents and Settings\user1\Desktop\Responses</ResponseFolder>
    <ArchiveMessages>Yes</ArchiveMessages>
    <ArchiveFolder>C:\Documents and Settings\user1\Desktop\Archive</ArchiveFolder>
    <Priority>1</Priority>

    <!--Custom elements - these can be anything-->
    <Currency>EUR</Currency>
    <AccountingSystem>HHGKOL</AccountingSystem>
</Partner>

The result here would be:

<Currency>EUR</Currency>
<AccountingSystem>HHGKOL</AccountingSystem>
  • 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-13T06:19:31+00:00Added an answer on June 13, 2026 at 6:19 am

    You can define a list of mandatory names and use LINQ to XML to filter:

     var mandatoryElements = new List<string>() {
                       "MandatoryElement1", 
                       "MandatoryElement2", 
                       "MandatoryElement3"
                    };
    
     var result = xDoc.Root.Descendants()
                      .Where(x => !mandatoryElements.Contains(x.Name.LocalName));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that reads from XML file. It gets five strings (groupId,
I have an XML file with data stored like this: <myxml> <item name=column18>88744544</item> <item
I have an application that can import an XML file through this terminal command
So I have this pretty large XML file (40MB) that I'll have to repeatedly
I have this xml file which has text init. i.e Hi my name is
I have this xml file <?xml version=1.0 encoding=UTF-8?> <bo:C837ClaimParent xsi:type=bo:C837ClaimParent xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:bo=http://somelongpathHere/process/bo> <claimAux> ...
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have this inside my spring xml file: <object type=Test.Web.Utilities.TestClass, Test.Web singleton=false id=TestClass> <property

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.