Forum Discussion

jbudd3681's avatar
jbudd3681
Visitor
10 years ago

xml <item> tag c#

Hello Everyone I have been working on creating a channel using the Video Player template, I am trying to create a dynamic XML page using C# to pull information from a database. all the examples i see shows when you create your item tag you are suppose to put the sdimg and hd img url with it. Every time i try i get an error. is any one familar with C# that could possibly help. or is there a tag that is a child of the Item we can use for the posters? Thanks in advance Justin

xml.WriteStartElement("item" + @" sdImg = ""http://rokudev.roku.com/rokudev/examples/videoplayer/images/JeffHan.jpg"" hdImg = ""http://rokudev.roku.com/rokudev/examples/videoplayer/images/JeffHan.jpg""");
xml.WriteElementString("title", reader[1].ToString());
xml.WriteStartElement("media");
xml.WriteElementString("contentType", "Talk");
xml.WriteElementString("contentQuality", "SD");
xml.WriteElementString("streamFormat", "mp4");
xml.WriteElementString("StreamUrl", "http://lofbc-media.s3.amazonaws.com/" + year + "/Video/mp4/" + reader[8].ToString().Replace("flv", "mp4"));
xml.WriteEndElement();
xml.WriteElementString("synopsis", reader[20].ToString() + " " + reader[18].ToString() + " " + reader[19].ToString());
xml.WriteElementString("genres", "religion");

5 Replies

  • for some reason its still not pulling the pictures to roku below is the xml that i point to http://www.lofbc.org/dev/roku/

    <item item="sdImg ='http://www.lofbc.org/roku/img/SDdefault.jpg' hdImg ='http://www.lofbc.org/roku/img/HDdefault.jpg'">
    <title>Humility is Strife Free</title>
    <contentId>2</contentId>
    <media>
    <contentType>Talk</contentType>
    <contentQuality>SD</contentQuality>
    <streamBitrate>1500</streamBitrate>
    <streamFormat>mp4</streamFormat>
    <StreamUrl>
    http://lofbc-media.s3.amazonaws.com/2015/Video/mp4/20150125.mp4
    </StreamUrl>
    </media>
    <synopsis>Pastor Stephen Fraser</synopsis>
    <genres>religion</genres>
    <runtime>0</runtime>
    </item>


    And this is my C#

    protected void Page_Load(object sender, EventArgs e)
    {
    //clears previous output
    Response.Clear();
    Response.ContentType = "text/xml";

    //XML Declartion tag
    XmlTextWriter xml = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
    xml.WriteStartDocument();

    //Starts feed
    xml.WriteStartElement("feed");
    try
    {
    SqlDataReader reader;
    //database connection
    SqlConnection con = new SqlConnection(" ****;");
    SqlCommand cmd = new SqlCommand(@"SELECT * FROM tbl_roku r INNER JOIN tbl_media_ministers m on
    r.MinisterID = m.ID ORDER BY CreatedDate", con);
    con.Open();
    reader = cmd.ExecuteReader();
    while (reader.Read())
    {
    var pubDate = reader[3].ToString();
    var year = DateTime.Parse(pubDate).ToString("yyyy");
    var sdImg = reader[6].ToString();
    var hdImg = reader[7].ToString();

    if (sdImg == "")
    {
    sdImg = "SDdefault.jpg";
    }
    if(hdImg == "")
    {
    hdImg = "HDdefault.jpg";
    }

    xml.WriteStartElement("item");
    xml.WriteAttributeString("item","sdImg ='http://www.lofbc.org/roku/img/" + sdImg + "' hdImg ='http://www.lofbc.org/roku/img/" + hdImg +"'");
    xml.WriteElementString("title", reader[1].ToString());
    xml.WriteElementString("contentId", reader[0].ToString());
    xml.WriteStartElement("media");
    xml.WriteElementString("contentType", "Talk");
    xml.WriteElementString("contentQuality", "SD");
    xml.WriteElementString("streamBitrate", "1500");
    xml.WriteElementString("streamFormat", "mp4");
    xml.WriteElementString("StreamUrl", "http://lofbc-media.s3.amazonaws.com/" + year + "/Video/mp4/" + reader[5].ToString().Replace("flv", "mp4"));
    xml.WriteEndElement();
    xml.WriteElementString("synopsis", reader[11].ToString() + " " + reader[9].ToString() + " " + reader[10].ToString() + " " + reader[4].ToString());
    xml.WriteElementString("genres", "religion");
    xml.WriteElementString("runtime", "0");
    xml.WriteEndElement();
    }
    reader.Close();
    con.Close();
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    xml.WriteEndElement();
    xml.WriteEndDocument();
    xml.Flush();
    xml.Close();
    Response.End();
    }
    }

    The last question i have is on runtime how should that be formated all the examples show what i thought were seconds but they don't add up when i compute them.

    Thanks

  • xml.WriteAttributeString("sdImg", "http://www.lofbc.org/roku/img/" + sdImg);
    xml.WriteAttributeString("hdImg", "http://www.lofbc.org/roku/img/" + hdImg);

    runtime should be an integer representing the length of the movie in seconds.