C# 如何加上“:&引用;Xml中XAttribute名称中的(命名空间前缀)
我有一个xml文件,在silverlight中使用C# 如何加上“:&引用;Xml中XAttribute名称中的(命名空间前缀),c#,xml,xml-namespaces,C#,Xml,Xml Namespaces,我有一个xml文件,在silverlight中使用 doc.Descendants(xamlparent).FirstOrDefault().Add(new XAttribute("x:Class","WorkflowConsoleApplication1.modify")); 但在此情况下:“:”十六进制会导致错误。如何在属性名称中添加此十六进制。这可能吗?您必须查看映射到x命名空间前缀的命名空间的URI。查看XML文档的顶部,它将包含类似于xmlns:x=”的内容http://schema
doc.Descendants(xamlparent).FirstOrDefault().Add(new XAttribute("x:Class","WorkflowConsoleApplication1.modify"));
但在此情况下:“:”十六进制会导致错误。如何在属性名称中添加此十六进制。这可能吗?您必须查看映射到
x
命名空间前缀的命名空间的URI。查看XML文档的顶部,它将包含类似于xmlns:x=”的内容http://schemas.microsoft.com/winfx/2006/xaml“
然后,使用上面的完整XML命名空间URI实例化XAttribute
,如下所示:
new XAttribute(XName.Get("Class", "http://schemas.microsoft.com/winfx/2006/xaml"), "WorkflowConsoleApplication1.modify")
进一步阅读:
- 关于维基百科