Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jbudd3681
Visitor

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");
0 Kudos
5 REPLIES 5
belltown
Roku Guru

Re: xml <item> tag c#

sdimg and hdimg are attributes of the <item> element, so you need to use WriteAttributeString for each of them. Here's an example: https://msdn.microsoft.com/en-us/library/y13bc3d8%28v=vs.110%29.aspx
0 Kudos
jbudd3681
Visitor

Re: xml <item> tag c#

Thank you soo much i was stumped
0 Kudos
jbudd3681
Visitor

Re: xml <item> tag c#

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
0 Kudos
belltown
Roku Guru

Re: xml <item> tag c#


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.
0 Kudos
jbudd3681
Visitor

Re: xml <item> tag c#

Thank you looks like i was trying to make it harder than it was..
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.