[英]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.