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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:14:13+00:00 2026-05-28T05:14:13+00:00

I have an Xml document: <?xml version=1.0 encoding=utf-8?> <Family xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <Person member=father id=0>

  • 0

I have an Xml document:

<?xml version="1.0" encoding="utf-8"?>
<Family xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Person member="father" id="0">
    <Surname>Smith</Surname>
    <Forename>Robert</Forename>
      <Person member="son" id="1">
        <Surname>Smith</Surname>
        <Forename>Sam</Forename>
          <Person member="son" id="2">
            <Surname>Smith</Surname>
            <Forename>Jeff</Forename>
          </Person>
      </Person>
      <Person member="daughter" id="3">
        <Surname>Smith</Surname>
        <Forename>Sarah</Forename>
      </Person>
  </Person>
</Family>

…and a few supporting classes as follows:

   [XmlRoot]
   public class Family {

      [XmlElement]
      public List<Person> Person;
   }

   public class Person {

      [XmlAttribute("member")]
      public MemberType Member { get; set; }

      [XmlAttribute("id")]
      public int Id { get; set; }

      [XmlElement]
      public string Surname { get; set; }

      [XmlElement]
      public string Forename { get; set; }

      [XmlElement("Person")]
      public List<Person> People;
   }

   public enum MemberType {
      Father,
      Mother,
      Son,
      Daughter
   }

Now, say Family has a method defined as such:

public IEnumerable<Person> Find (Func<Person, bool> predicate) {
    //  also, I know that this SelectMany will not work - assume this foreach works
    //  on a flattened list of people
    foreach (var p in family.Person.SelectMany()) {
        if(predicate(p)) {
            yield return p;
        }
    }
}

…but I don’t want to deserialize the Xml to the Family and Person classes. I would like to simply load the XDocument and query that directly – but working with XElement, XAttribute, and XName is not that friendly when providing an API. I realize that I need the classes – Family & Person – but they are simply models.

Can I have a Find method where I can pass something like:

IEnumerable<Person> people = someBusinessObj.Find(p => p.Forename == "Jeff");

Update
I would prefer a solution that does not involve an open-source project (as @MartinHonnen refers).

  • 1 1 Answer
  • 1 View
  • 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-28T05:14:14+00:00Added an answer on May 28, 2026 at 5:14 am

    Why do you not want to deserialize the XML into objects? This will give you exactly the programmatic interface you require. I would:

    1. Deserialize using the XmlSerializer class.
    2. Allow you users to query via Linq-to-Objects.

    All this requires very little effort to implement!

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

Sidebar

Related Questions

I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0
If we have an XML document: <?xml version=1.0 encoding=utf-8?> <STICKERINFO> <ORDER> <NUMBER>0171467783</NUMBER> <STICKER> <ARTICLE>03359140001</ARTICLE>
i have xml document like this: <?xml version=1.0 encoding=utf-8 ?> <demographics> <country id=1 value=USA>
I have an XML document being sent to me by HTTP POST: <?xml version=1.0
I have generated this WSDL file... <?xml version=1.0 encoding=UTF-8 standalone=yes?> <!-- Generated by JAX-WS
I have an xml file which i create myself. <?xml version='1.0' encoding='utf-8' ?> <Root>
Here's an example of an XML file created in InfoPath: <?xml version=1.0 encoding=UTF-8?> <?mso-infoPathSolution
Summary Attempting to read and serialize XML documents that have a UTF-16 encoding and

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.