Purify Embedding YouTube Videos method in C#

后端 未结 1 1370
春和景丽
春和景丽 2021-01-16 16:23

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

So method input would be:



        
                      
相关标签:
1条回答
  • 2021-01-16 17:03

    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("<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>") %>

    or something like that.

    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;
    }
    
    0 讨论(0)
提交回复
热议问题