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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:23:37+00:00 2026-06-06T19:23:37+00:00

I have a C# MVC application which I need to output the following data

  • 0

I have a C# MVC application which I need to output the following data to a view:

            <versions>
              <product>true</product>
              <type>city</type>
              <factory name="Demme" url="http://test1.com" thumbnail="http://test3.com/img1" interval="10" />
              <factory name="Vollick" url="http://test2.com" thumbnail="http://test3.com/img1" interval="10" />
              <factory name="Tony" url="http://test3.com" thumbnail="http://test3.com/img1" interval="10" />
            </versions>

The above data comes from a SQL table/column which stores the data as a XML data type.
Can somone give me a code example to extract the values of the elements(maybe assign each value to variable) so I can pass it to a view?

So I need to get the values “true” , “City”, “Demme” , “http://test1.com&#8221;, “http://test3.com/img1&#8230;.and so on.

Whats the best way to present this data to a view?

  • 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-06T19:23:39+00:00Added an answer on June 6, 2026 at 7:23 pm

    My idea is to create classes, corresponding to your Xml file, a Version class, a Factory class. Load the xml file, and then pass it to your class that return your data, here is how I do it :

    The Version class :

    public class Version
    {
        public bool IsProduct { get; set; }
        public string City { get; set; }
        public List<Factory> Factories { get; set; }
    
        //Create a version
        public Version(XElement xVersion)
        {
            IsProduct = Convert.ToBoolean(xVersion.Element("Product").Value);
            City = xVersion.Element("City").Value;
            Factories = Factory.GetFactories(xVersion);
        }
    
        //Get the list of versions
        public static List<Version> GetVersions(XElement xDocument)
        {
            if (xDocument == null)
                return null;
    
            List<Version> list = new List<Version>();
            var xVersions = xDocument.Elements("Version");
    
            foreach (var xVersion in xVersions)
            {
                list.Add(new Version(xVersion));
            }
    
            return list;
        }
    }
    

    The Factory class :

    public class Factory
    {
        public string Name { get; set; }
        public string Url { get; set; }
        public string Thumbnail { get; set; }
        public string Interval { get; set; }
    
        //Create a factory
        public Factory(XElement xFactory)
        {
            Name = xFactory.Attribute("Name").Value;
            Url = xFactory.Attribute("Url").Value;
            Thumbnail = xFactory.Attribute("Thumbnail").Value;
            Interval = xFactory.Attribute("Interval").Value;
        }
    
        //Get the factories of a version
        public static List<Factory> GetFactories(XElement xVersion)
        {
            var xFactories = xVersion.Elements("Factory");
            if (xFactories == null)
                return null;
    
            List<Factory> list = new List<Factory>();
    
            foreach (var xFactory in xFactories)
            {
                list.Add(new Factory(xFactory));
            }
    
            return list;
        }
    }
    

    And last, in your MCV Controller :

    private void myMethod()
        {
            var xDocument = XElement.Load("XmlFilePath");
            var versions = Version.GetVersions(xDocument);
    
            //And then, pass the -versions- to your typed view ^^
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using sping3 mvc in my application. I have some entities which need
I have a Spring MVC application which uses FreeMarker as View technology (But maybe
I have an ASP MVC application which uses some silverlight applications in the View.
I have a weird need in an ASP.NET MVC 3 application which blocks my
I have an ASP.NET MVC application which uses plain HTML. I quickly need to
I am creating a .NET MVC application and I have a view in which
I have ASP.NET MVC web application. I need to deploy it which consists of:
I have MVC webApi application which works with Unity . I have to resolve
I have an MVC application which is my marketing website, and two other regular
I have an MVC application which has a set of fields for contact details

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.