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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:21:56+00:00 2026-05-16T22:21:56+00:00

Iv got two DB tables. One containing types(Id, Name) and the other holds datapoints

  • 0

Iv got two DB tables. One containing types(Id, Name) and the other holds datapoints (RefId, Date, Value) that are referenced by the types. I need to create a XML file with the following strukture:

<?xml version='1.0' encoding='utf-8' ?>
<root>
   <type>
      <name></name>
      <data>
         <date></date>
         <temp></temp>
      </data>
      <data>
         <date></date>
         <temp></temp>
      </data>
      <data>
         <date></date>
         <temp></temp>
      </data>
   </type>
</root> 

And iv got the following code to do this

    public XmlDocument HelloWorld()
    {
        string tmp = "";
        try
        {
            sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["NorlanderDBConnection"].ConnectionString;
            DataContext db = new DataContext(sqlConn.ConnectionString);

            Table<DataType> dataTypes = db.GetTable<DataType>();
            Table<DataPoints> dataPoints = db.GetTable<DataPoints>();

            var dataT =
                        from t in dataTypes
                        select t;
            var dataP =
                from t in dataTypes
                join p in dataPoints on t.Id equals p.RefId
                select new
                {
                    Id = t.Id,
                    Name = t.Name,
                    Date = p.PointDate,
                    Value = p.PointValue
                };

            string xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><root></root>";

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.LoadXml(xmlString);

            int count = 0;
            foreach (var dt in dataT)
            {
                XmlElement type = xmldoc.CreateElement("type");
                XmlElement name = xmldoc.CreateElement("name");
                XmlNode nameText = xmldoc.CreateTextNode(dt.Name);
                name.AppendChild(nameText);
                type.AppendChild(name);                    

                foreach(var dp in dataP.Where(dt.Id = dp.RefId))
                {
                    XmlElement data = xmldoc.CreateElement("data");
                    XmlElement date = xmldoc.CreateElement("date");
                    XmlElement temp = xmldoc.CreateElement("temp");

                    XmlNode dateValue = xmldoc.CreateTextNode(dp.Date.ToString());
                    date.AppendChild(dateValue);

                    XmlNode tempValue = xmldoc.CreateTextNode(dp.Value.ToString());
                    temp.AppendChild(tempValue);

                    data.AppendChild(date);
                    data.AppendChild(temp);

                    type.AppendChild(data);
                }

                xmldoc.DocumentElement.AppendChild(type);

            }

            return xmldoc;
        }
        catch(Exception e)
        {
            tmp = e.ToString();
        }

        return null;
    }

    [Table(Name="DataTypes")]
    public class DataType
    {
        [Column(IsPrimaryKey = true)]
        public long Id;
        [Column]
        public string Name;
    }
    [Table(Name="DataPoints")]
    public class DataPoints
    {
        [Column]
        public long RefId;
        [Column]
        public DateTime PointDate;
        [Column]
        public double PointValue;
    }

This is not a working code. Im having problems with LINQ and the inner joins. Could someone please help me to get the correct strukture. I hope its kinda clear what im trying to achive.

Best Regards
Marthin

  • 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-16T22:21:57+00:00Added an answer on May 16, 2026 at 10:21 pm
    var result =
        new XDocument(new XElement("root",
            from dt in dataTypes
            join dp in dataPoints on dt.Id equals dp.RefId
            select new XElement("type",
                new XElement("name", dt.Name),
                new XElement("data",
                    new XElement("date", dp.PointDate),
                    new XElement("temp", dp.PointValue)))));
    

    var result =
        new XDocument(new XElement("root",
            from dt in dataTypes
            select new XElement("type",
                new XElement("name", dt.Name),
                from dp in dataPoints
                where dp.RefId == dt.Id
                select new XElement("data",
                    new XElement("date", dp.PointDate),
                    new XElement("temp", dp.PointValue)))));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got two tables. One that holds all availeble trophys and one that holds
I've got two tables, one holds reservations for a room, and the other is
I've got two tables. One of them contains quotes and the other one lists
I got two tables one below the other. I want to move it up
I've got two tables (articles and tags) that have a one-to-many relationship. I remember
Hello I have two mysql tables one that holds username and password second that
I've got one table containing some sort of items , and two tables (
I've got two tables, one for openings and the other for bookings. An entry
I've got two tables. One is Corporations (e.g., one record is for Taco Bell).
I've got two tables: TableA ------ ID, Name TableB ------ ID, SomeColumn, TableA_ID (FK

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.