Fiv*_*ols 4 html c# asp.net xml-namespaces
我想<HTML>在asp.net中为元素添加两个额外的xml命名空间:
采取:
<html xmlns="http://www.w3.org/1999/xhtml" >
Run Code Online (Sandbox Code Playgroud)
制作(添加facebook开放图形命名空间):
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
Run Code Online (Sandbox Code Playgroud)
我如何访问<HTML>后面的代码中的元素并添加命名空间?
bre*_*dan 12
你可以像任何其他元素一样做.在你的aspx中,只需将html标记标记为runat服务器:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" id="html_tag" runat="server">
Run Code Online (Sandbox Code Playgroud)
在您的代码中只需添加属性:
protected void Page_Load(object sender, EventArgs e)
{
html_tag.Attributes.Add("xmlns:og","http://ogp.me/ns#");
html_tag.Attributes.Add("xmlns:fb", "http://www.facebook.com/2008/fbmls");
}
Run Code Online (Sandbox Code Playgroud)
这当然不必通过代码完成,只能放在您的aspx中,除非您只想在某些条件下包含这些属性.