[英]Writing out namespace attributes in LINQ to XML
我想通过C#使用LINQ to XML编写以下XAML。
<Activity x:Class="WorkflowConsoleApplication1.Activity1" mva:VisualBasic.Settings="Assembly references and imported namespaces for internal implementation"> </Activity>
如何指定XNamespace来实现上述输出?
这段代码可以做到:
var el = new XElement(
"Activity",
new XAttribute(XName.Get("Class", "SomeNamespace"), "WorkflowConsoleApplication1.Activity1"),
new XAttribute(
XName.Get("VisualBasic.Settings", "SomeOtherNamespace"),
"Assembly references and imported namespaces for internal implementation"));
Console.WriteLine(el.ToString());
注意如何不指定前缀,而是指定这些属性所属的名称空间。 这是设计使然,并且与XML规范一致。 前缀将自动生成,或者如果包含的另一个元素的子元素已经为您使用的名称空间定义了前缀,则从包含的元素中提取前缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.