linq to xml

简介: 无废话,直接上: 1 try 2 { 3 XDocument xdoc = new XDocument( 4 new XProcessingInstruction("UserConfigHelp", "xmlns:xsi='http://www.

无废话,直接上:

 1             try
 2             {
 3                 XDocument xdoc = new XDocument(
 4                    new XProcessingInstruction("UserConfigHelp", "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'"),
 5                    new XComment("开始配置用户、主题、模板、模框、模块关系"),
 6                    new XElement("UserConfigInfoList",
 7                             new XElement("UserConfigInfo",
 8                                     new XAttribute("id", "1"),
 9                                     new XAttribute("userGuid", ""),
10                                     new XAttribute("userName", userName),
11                                     new XAttribute("displayName", ""),
12                                     new XAttribute("departmentGuid", ""),
13                                     new XAttribute("departmentName", ""),
14                                     new XElement("ThemeTemplateInfoList",
15                                     from tt in ttList
16                                     select new XElement("ThemeTemplateInfo",
17                                                     new XAttribute("recordNumberID", tt.ttTempCinfigNum),
18                                                     new XAttribute("disaplyName", tt.ttUserTempInfo.DisaplayName),
19                                                     new XAttribute("englishName", tt.ttUserTempInfo.EnglishName),
20                                                     new XAttribute("themeID", tt.ttThemeId),
21                                                     new XAttribute("themeLanguage", tt.ttTemplateInfo.Language == 1 ? "cn" : "en"),
22                                                     new XAttribute("themeName", tt.ttThemeName),
23                                                     new XAttribute("templateID", tt.ttTemplateInfo.ID),
24                                                     new XAttribute("templateLanguage", tt.ttTemplateInfo.Language == 1 ? "cn" : "en"),
25                                                     new XAttribute("templateName", tt.ttTemplateInfo.TempName),
26                                                     new XAttribute("templateUrl", tt.ttTemplateInfo.TempUrl),
27                                                     new XAttribute("navUrl", tt.ttUserTempInfo.NavUrl),
28                                                     new XElement("TemplateDetailModuleInfoList",
29                                                     from utm in tt.ttUserTempModuleList
30                                                     select new XElement("TemplateDetailModuleInfo",
31                                                                     new XAttribute("templateDetailID", utm.TempDetailD),
32                                                                     new XAttribute("templateDetailName", utm.TempLateDetail.RectangleName),
33                                                                     new XAttribute("templateDivID", utm.TempLateDetail.DivID),
34                                                                     new XAttribute("moduleID", utm.ModuleID),
35                                                                     new XAttribute("moduleLanguage", utm.ModuleInfo.Language == 1 ? "cn" : "en"),
36                                                                     new XAttribute("moduleDisplayName", utm.ModuleInfo.DisplayName),
37                                                                     new XAttribute("moduleClassName", utm.ModuleInfo.ClassName),
38                                                                     new XAttribute("moduleUrl", utm.ModuleInfo.Url),
39                                                                     new XAttribute("configRecordNum", utm.ModuleInfo.RecordNum),
40                                                                     new XAttribute("isAsyncLoad", utm.ModuleInfo.IsAsyncLoad),
41                                                                     new XAttribute("customParameters", utm.CustomParameters)
42                                                             )
43                                                      )
44 
45                                             )
46                                     )
47 
48                                 )
49                         ),
50                    new XComment("结束")
51                );
52                 保存此结构
53                 xdoc.Save(xmlPath);
54             }
55             catch (Exception ex)
56             {
57                 Console.WriteLine(ex.ToString());
58             }
View Code

生成的xml:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <?UserConfigHelp xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'?>
 3 <!--开始配置用户、主题、模板、模框、模块关系-->
 4 <UserConfigInfoList>
 5   <UserConfigInfo id="1" userGuid="" userName="dengyi" displayName="" departmentGuid="" departmentName="">
 6     <ThemeTemplateInfoList>
 7       <ThemeTemplateInfo recordNumberID="UTM-201703020001" disaplyName="通用门户" englishName="tymh" themeID="2" themeLanguage="cn" themeName="default" templateID="2" templateLanguage="cn" templateName="模板哈哈哈" templateUrl="sfs" navUrl="Controls/NAV/CommonNavControl.ascx">
 8         <TemplateDetailModuleInfoList>
 9           <TemplateDetailModuleInfo templateDetailID="7" templateDetailName="新闻" templateDivID="3123" moduleID="5" moduleLanguage="cn" moduleDisplayName="新闻公告" moduleClassName="Notices" moduleUrl="Controls/ADM/News.ascx " configRecordNum="Module-201702220003" isAsyncLoad="false" customParameters="111,222,333" />
10           <TemplateDetailModuleInfo templateDetailID="8" templateDetailName="公告" templateDivID="no" moduleID="6" moduleLanguage="cn" moduleDisplayName="BI" moduleClassName=".gztx /.index" moduleUrl="HX.MVC.Application\themes\default\css\bigroll.css" configRecordNum="Module-201702220004" isAsyncLoad="false" customParameters="111,222,333" />
11           <TemplateDetailModuleInfo templateDetailID="9" templateDetailName="安置" templateDivID="not" moduleID="9" moduleLanguage="cn" moduleDisplayName="信息系统" moduleClassName="1" moduleUrl="1" configRecordNum="Module-201702220007" isAsyncLoad="false" customParameters="111,222,333" />
12         </TemplateDetailModuleInfoList>
13       </ThemeTemplateInfo>
14     </ThemeTemplateInfoList>
15   </UserConfigInfo>
16 </UserConfigInfoList>
17 <!--结束-->
xml

 

目录
相关文章
|
XML 开发框架 .NET
XML基础学习02&lt;linq to xml&gt;
XML基础学习02&lt;linq to xml&gt;
162 0
XML基础学习02&lt;linq to xml&gt;
|
XML 存储 开发框架
Linq To XML总结
Linq To XML总结
96 0
Linq To XML总结
|
XML JavaScript .NET
|
XML JavaScript .NET