html
  • vb.net
  • winforms
  • 2012-03-25 32 views 0 likes 
    0

    更改HTML源代碼我有下面的結構HTML頁面中的WinForms

    <video controls="controls" width="480" height="208" id="video1"> 
         <source src="http://devfiles.myopera.com/articles/2642/sintel-trailer.ogv" type='video/ogg; codecs="theora, vorbis"'> 
         <source src="http://devfiles.myopera.com/articles/2642/sintel-trailer.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'> 
    </video> 
    

    有在上面的代碼沒有問題。我需要使用OpenfileDialog替換視頻的src與我從本地資源(即桌面或任何其他文件夾)中選擇的視頻替換文件名,並用其擴展名代替文件名替換src="http://"。例如,如果選擇mymovie.mp4,我會讀取html模板文件,並用mymovie.mp4替換該視頻的src標記。

    那麼我該如何修改它?

    回答

    0

    我認爲,無論是正則表達式可以在這裏工作:

    Dim m As Match = Regex.Match(inputString, _ 
           @"<source src=\"(.*?)\"", _ 
           RegexOptions.IgnoreCase) 
    
    If (m.Success) Then 
         ' Loop through each group (which will contain the href value) 
         ' Open with that href and just do a replace on the original string 
         ' m.Groups(1).Value 
    End If 
    

    或者,你可以在HTML加載到一個XmlDocument並取代它的方式。

    Dim m_xmld As XmlDocument 
    Dim m_nodelist As XmlNodeList 
    Dim m_node As XmlNode 
    
    ' Create the XML Document 
    m_xmld = New XmlDocument() 
    
    ' Load the Xml file 
    m_xmld.Load("html string here") 
    
    ' Get the list of name nodes 
    m_nodelist = m_xmld.SelectNodes(@"//video/source") 
    
    For Each m_node In m_nodelist 
    ' Get the attribute value 
    Dim srcValue = m_node.Attributes.GetNamedItem("src").Value 
    
    ' Load the value and store new value 
    ' Replace the attribute with the new 
    m_node.Attributes.SetNamedItem(NEWVALUE) 
    
    Next 
    
    0

    您可以使用JavaScript這樣的: 1.更改您的html代碼:

    <video id="myVideo" controls="controls" width="480" height="208" id="video1"> 
    

    2.實現此功能:

    function gid(id){ 
        var d=document; 
        if(d.getElementById){ 
         return d.getElementById(id); 
        } 
        else if(d.all){ 
         return d.all[id]; 
        } 
        else if(d.layers){ 
         return d.layers[id]; 
        } 
        return null; 
    } 
    function changeVideoContent(){ 
        var content = '<source src="http://... and all you desire...'; 
        gid("myVideo").innerHTML = content; 
    } 
    

    3.綁定changeVideoContent功能與形式使用onSubmit,onClick或其他事件。

    相關問題