净化在C#中嵌入YouTube视频的方法 [英] Purify Embedding YouTube Videos method in C#

查看:375
本文介绍了净化在C#中嵌入YouTube视频的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么会看的方法在C#中的净化嵌入的YouTube视频标记?

How would look a method in C# that "purify" an embedded YouTube video markup?

所以,法输入方式是:

<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/gtNlQodFMi8&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>



输出:

Output:

<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/gtNlQodFMi8">
<param name="movie" value="http://www.youtube.com/v/gtNlQodFMi8" />



YouTube嵌入式视频标记是有问题因为内嵌样式(宽,高),它是不是XHTML有效的。

YouTube embedded video markup is problematic because of the inline style (width, height) and it is not XHTML valid.

推荐答案

那么你总是可以写一个C#方法这将输出的代码,你希望给予一定的投入,在这种情况下,对象的XML,然后分析它,并拉出你想要的比特和构建你的代码和输出,然后从ASPX页面,你只需用叫它服务器代码,这样

Well you could always write a C# method that will output the code that you want given a certain input, in this case the XML of the object, then parse it and pull out the bits you want and construct your code and output it, then from the aspx page you simply call it with server code, like this

<%MyYoutubeUtils.ShowEmebddedVideo(<对象宽度=425HEIGHT =344>< ; PARAM NAME =电影值=htt​​p://www.youtube.com/v/gtNlQodFMi8&hl=en&fs=1>< /参数>< PARAM NAME =的allowFullScreen值=真正的>< /参数><嵌入SRC =http://www.youtube.com/v/gtNlQodFMi8&hl=en&fs=1类型=应用/的X冲击波闪光的allowFullScreen = 真WIDTH =425HEIGHT =344>< /嵌入>< /对象>)%>

或类似的东西。

好吧,我不是100%确定的语法,但是这应该给你一个开始。

Ok I am not 100% sure of the syntax, but this should give you a start.

public static string ShowEmbeddedVideo(string youtubeObject)
{
    var xdoc = XDocument.Parse(youtubeObject);
    var returnObject = string.Format("<object type=\"{0}\" data=\{1}\"><param name=\"movie\" value=\"{1}\" />",
        xdoc.Root.Element("embed").Attribute("type").Value,
        xdoc.Root.Element("embed").Attribute("src").Value);
    return returnObject;
}

这篇关于净化在C#中嵌入YouTube视频的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆