SetAttribute xlink:href 为XML添加带":"的属性

来源:互联网 发布:淘宝相纸区别 编辑:程序博客网 时间:2024/06/15 12:34
svg中经常用到 xlink:href ,而使用SetAttribute添加属性会报错误,下面给出正确的添加方法:

XmlElement me = doc.CreateElement("", Name, doc.NamespaceURI);
if (s == "xlink:href")
{//添加 xlink:href 属性
    XmlAttribute node = doc.CreateAttribute("xlink", "href", "http://www.w3.org/2000/xlink");
    node.Value = _atts[s].ToString();
    me.Attributes.Append(node);

}
else
{//添加一般属性
    me.SetAttribute(s, doc.NamespaceURI, _atts[s].ToString());
}

文章来源于 http://www.cnblogs.com/wf225 版权归原作者所有
原创粉丝点击