Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何加上“:&引用;Xml中XAttribute名称中的(命名空间前缀)_C#_Xml_Xml Namespaces - Fatal编程技术网

C# 如何加上“:&引用;Xml中XAttribute名称中的(命名空间前缀)

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

我有一个xml文件,在silverlight中使用

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")
进一步阅读:

  • 关于维基百科