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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:22:04+00:00 2026-05-13T16:22:04+00:00

I am experimenting with using xml as a database for small CMS, like gallery

  • 0

I am experimenting with using xml as a database for small CMS, like gallery or staff profiles
etc

however being all subsonic minded i am stuck on how i bind my xml document to a modelclass
so that i can then use that class for strongly typed views:

here is my model class:

[XmlRoot("employee")]
public class EmployeesModel
{
    [Required]
    [DisplayName("Name: ")]
    [XmlElement("employeeName")]
    public string employeeName { get; set; }

    [Required]
    [DisplayName("Position: ")]
    [XmlElement("employeePosition")]
    public string employeePosition { get; set; }

    [Required]
    [DisplayName("Description")]
    [XmlElement("employeeDescription")]
    public string employeeDescription { get; set; }

    [Required]
    [DisplayName("Photo: ")]
    [XmlElement("employeePhoto")]
    public string employeePhoto { get; set; }

    [Required]
    [DisplayName("ID: ")]
    [XmlElement("employeeID")]
    public int employeeID { get; set; }
}

and here is my code:

XDocument xmlDoc = XDocument.Load(Server.MapPath("~/App_Data/employees.xml"));

        var model = (from xml in xmlDoc.Descendants("employee")
                                             select xml) as IEnumerable<EmployeesModel>;

        return View(model);

the XML

<?xml version="1.0" encoding="utf-8" ?>
<employees>
<employee>
    <employeeName>David parker</employeeName>
     <employeePosition>Senior Web Developer</employeePosition>
     <employeeDescription>This is a test description<br>feele free to add something here.</employeeDescription>
     <employeePhoto>mypic.jpg</employeePhoto>
    <employeeID>1</employeeID></employee></employees>

the xml side work but model is always empty, however i get no runtime erros when trying to bind, i know there is more i should do here but i need some help.

for clarity i am using asp.net mvc 2 rc 2

thanks

  • 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-05-13T16:22:04+00:00Added an answer on May 13, 2026 at 4:22 pm

    You need to deserialize the XML into objects. You cannot simply cast XML as objects. When you say as IEnumerable<EmployeesModel>, you’ll get a null since the types aren’t compatible. Your code could look something like this:

    var serializer = new XmlSerializer(typeof(EmployeesModel));
    var model = 
        from xml in xmlDoc.Descendants("employee")
        select serializer.Deserialize(xml.CreateReader()) as EmployeesModel;
    

    Another option you could consider is to project the XElements into EmployeesModel objects, like this:

    var model =
        from xml in xmlDoc.Descendants("employee")
        select new EmployeesModel {
            employeeName = (string)xml.Element("employeeName"),
            employeePosition = (string)xml.Element("employeePosition"),
            employeeDescription = (string)xml.Element("employeeDescription"),
            employeePhoto = (string)xml.Element("employeePhoto"),
            employeeID = (int)xml.Element("employeeID"), };
    

    As you can see, that can get tedious. However, it may be appropriate. If your XML file represents all employee data but your view shows only a subset of the data or the data in a different structure, you probably don’t want your view model to be a direct copy of the contents of your data store.

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

Sidebar

Ask A Question

Stats

  • Questions 336k
  • Answers 337k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Problem solved, sort of. The problem was that I implemented… May 14, 2026 at 3:57 am
  • Editorial Team
    Editorial Team added an answer If you can reliably, dynamically create it, the don't check… May 14, 2026 at 3:57 am
  • Editorial Team
    Editorial Team added an answer Unless you do it by owner-drawn your only options are… May 14, 2026 at 3:57 am

Related Questions

WSS 3.0 List Service I am running GetListItems() on a Picture Library (name Pictures)
I am experimenting with using subversion to deploy updates to my ASP.Net application, one
I have these container objects (let's call them Container) in a list. Each of
I am experimenting with Jetpack and I would like to parse all the years
I am experimenting with calling delegate functions from a delegate array. I've been able

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.