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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:45:55+00:00 2026-06-02T15:45:55+00:00

I have xml (which I have no control over) which I needwant to deserialize

  • 0

I have xml (which I have no control over) which I needwant to deserialize with the XmlSerializer. My trouble is that I need to preserve the order among two different tags in a single list. Let me give an example:

<users>
    <luser>..some more elements..</luser>
    <luser>..some more elements..</luser>
    <admin>..different elements than in luser</admin>
    <luser>..some more elements..</luser>
    <admin>..different elements than in luser</admin>
    <luser>..some more elements..</luser>
    <admin>..different elements than in luser</admin>
<users>

Now, if I deserialze this the straight forward way, I end up with two lists, one for lusers and one for admins. However, the order they appear in is the implicit ID! (Which of course should have been an attribute or element in the xml but alas it is not)

I’ve tried to make a meta element like this

[XmlElement("luser"),XmlElement("admin")]
public List<Person> Person { get; set; }

with

public class Person
{
    public Luser Luser { get; set; }
    public Admin Admin { get; set; }
}

where the plan was to check the list to see if the entry a luser or an admin, and have the people wrapper maintain the order of the elements. However multiple XmlElement attributes on a single property seems to be illegal.

Another acceptable solution would be to end up with two lists but where each entry in each list had an ID I could use to get the original order.

I want this to be as clean as possible. Searching through the xml afterwards to find the order, manually extracting the tags, and similar, is something I would avoid and do as a very last resort.

  • 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-02T15:45:57+00:00Added an answer on June 2, 2026 at 3:45 pm

    Which of course should have been an attribute…

    Then make it an Attribute as soon as you can. Then work with the result.

    var doc = XDocument.Load(...);
    
    var fixeruppers = doc
          .Descendants("users")
          .Elements()
          .ToList();   // isolate us from any movements in the doc
    
    int id = 1; // base
    foreach (var fixer in fixeruppers)
       fixer.SetAttributeValue("Id", id++);
    
    XmlReader readerForDeserialize = doc.CreateReader();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm transforming some XML, which I have no control over, to XHTML. The XML
I'm using SimpleXml on Android to deserialize an xml which I have no control
I have added an easy compound control which loads its layout from a XML
I have an XML file which I need to parse using PHP and send
I'm trying to join two SQL tables, parent (which I have complete design control
I have some XML which contains records and sub records, like this: <data> <record
I have some XML which I'm trying to search: <debts> <section id=24 description=YYYYY> <section
I have an XML (first.xml) which looks like :: <?xml version=1.0 encoding=utf-8?> <saw:jobInfo xmlns:saw=com.analytics.web/report/v1.1>
I have an xml document which consists of a number of the following: -
I have an XML file which XML parser choke on. A part of it

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.