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

  • Home
  • SEARCH
  • 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 7971175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:34:33+00:00 2026-06-04T07:34:33+00:00

Im trying to create a page for a university project that dynamically displays a

  • 0

Im trying to create a page for a university project that dynamically displays a list of videos in a flash player from data stored in a Mysql database. i already have the player running correctly from a simple XML list but I need to get the right data from the database and convert it to an XML list to display the playlist according to the currently selected video.

The XML list looks like this:

 <?xml version="1.0" encoding="utf-8"?> 
<item> 
   <list name="A really awesome video of Declan's face." videotitle="Declan Video" link="0001.flv" > 
       <thumb>thumb/1.jpg</thumb> 
   </list> 
   <list name="Test content - Video of Wenlong and Jing" videotitle="Final matrix demo 2" link="test1.flv" > 
       <thumb>thumb/2.jpg</thumb> 
   </list> 
   <list name="Video of Wenlong and Jing" videotitle="Matrix film demo 1" link="test2.flv" > 
       <thumb>thumb/1.jpg</thumb> 
   </list> 
   <list name="Video of Wenlong and Jing" videotitle="Final matrix demo 2" link="test4.flv" > 
       <thumb>thumb/2.jpg</thumb> 
   </list> 
   <list name="Video of Wenlong and Jing" videotitle="Matrix film demo 1" link="wenlong1.flv" > 
       <thumb>thumb/1.jpg</thumb> 
   </list> 

   </list> 


</item>

Any ideas on how to best achieve this? Help would be greatly appreciated.

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-06-04T07:34:34+00:00Added an answer on June 4, 2026 at 7:34 am

    Have you tried just manually creating the XML file using XDocument from your results set?

    Now you havent provided any sample code for getting the data out of your MySql server, or no examples that should the parameters for reading the mysql data storeage. With little information can really just provide you with a basic method that takes a data table (with specific column names) and returns a simple formatted xml document.

    public static XDocument CreatePlaylist(System.Data.DataTable DataTable)
            {
                var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
                var xItem = new XElement("item");
                foreach (var row in DataTable.Rows.OfType<System.Data.DataRow>())
                    xItem.Add(new XElement("list",
                                new XAttribute("name", row["name"].ToString()),
                                new XAttribute("videotitle", row["videotitle"].ToString()),
                                new XAttribute("link", row["link"].ToString()),
                                new XElement("thumb", row["thumb"].ToString())));
                xDoc.Add(xItem);
                return xDoc;
            }
    

    That little snippet is simple, it simply accepts the datatable as a parameter and then creates a XDocument for you. Now the requirements are the datatable must have the columns name, videotitle, link and thumb.

    Now moving on you can simply call this method which will return the XDocument object, from there calling the .ToString() method of the XDocument will give you your xml. However there is a catch (there’s always a catch). The XDocument doesnt include the Xml Declaration when the .ToString() method is called. If you call the .Save() method it will output the Xml Declaration.

    I have another simple method that allows you to output the XDocument to a string with the Xml Declaration intact. This methods is as follows.

    public static string XDocToStringWithDeclaration(XDocument doc)
            {
                string xString;
                using (var sw = new System.IO.MemoryStream())
                {
                    using (var strw = new System.IO.StreamWriter(sw, System.Text.UTF8Encoding.UTF8))
                    {
                        doc.Save(strw);
                        xString = System.Text.UTF8Encoding.UTF8.GetString(sw.ToArray());
                    }
                }
                return xString;
            }
    

    You see that method will call the Save() method of the xDocument however will save it to a MemoryStream and then output the memorystream as a string.

    Now to tie it all together I have a simple console application that you can have a look at and understand how it all fit together.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var dt = new System.Data.DataTable();
                dt.Columns.Add("name");
                dt.Columns.Add("videotitle");
                dt.Columns.Add("link");
                dt.Columns.Add("thumb");
    
                for (int i = 0, j = 5; i <= j; i++)
                {
                    var row = dt.NewRow();
                    row["name"] = string.Format("video {0}", i);
                    row["videotitle"] = string.Format("video {0}", i);
                    row["link"] = string.Format("/someurl/video{0}.avi", i);
                    row["thumb"] = string.Format("/someurl/video{0}.png", i);
                    dt.Rows.Add(row);
                }
                var xmlDoc = CreatePlaylist(dt);
    
                Console.WriteLine(XDocToStringWithDeclaration(xmlDoc));
    
    
                Console.WriteLine("{0}Finished... Press a key", Environment.NewLine);
                Console.ReadKey();
    
            }
    
            public static string XDocToStringWithDeclaration(XDocument doc)
            {
                string xString;
                using (var sw = new System.IO.MemoryStream())
                {
                    using (var strw = new System.IO.StreamWriter(sw, System.Text.UTF8Encoding.UTF8))
                    {
                        doc.Save(strw);
                        xString = System.Text.UTF8Encoding.UTF8.GetString(sw.ToArray());
                    }
                }
                return xString;
            }
    
            public static XDocument CreatePlaylist(System.Data.DataTable DataTable)
            {
                var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
                var xItem = new XElement("item");
                foreach (var row in DataTable.Rows.OfType<System.Data.DataRow>())
                    xItem.Add(new XElement("list",
                                new XAttribute("name", row["name"].ToString()),
                                new XAttribute("videotitle", row["videotitle"].ToString()),
                                new XAttribute("link", row["link"].ToString()),
                                new XElement("thumb", row["thumb"].ToString())));
                xDoc.Add(xItem);
                return xDoc;
            }
        }
    }
    

    I hope this helps.

    Cheers,
    Nico

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

Sidebar

Related Questions

I'm trying to create a page that displays a list of employees. All the
I'm trying to create a page that displays statistics for every player. A sum
I am trying to create a page that displays a preview of all the
I am trying to create a page, named Archive.aspx , that displays all my
I am trying to create a page in my WordPress Admin Area that displays
I have been trying to create a page using views that will list down
I am trying to create a page to display a list of links for
I'm trying to create a page by using view 2. This page list all
I'm trying to create a page that contains a grid and searching. The issue
I am trying to create a login page that will send the user to

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.