转自:http://www.cnblogs.com/Bruce_H21/archive/2005/07/22/197932.html
前一阵子抽了一些时间看了一下缩水版的DNN(starter kit)---- [从二十四画生那里请教的DNN的学习方法]。
其中portal的用户配置文件portalCfg.xml还有该文件的操作类portalCfg.vb是实现灵活页面布局的关键。一开始觉得写操作类的portalCfg.vb文件很难,而且那么长的代码文件差不多2k多行,仔细看portalCfg.vb文件的头部包含这样的注释 :

' ------------------------------------------------------------------------------
'
 <autogenerated>
'
     This code was generated by a tool.
'
     Runtime Version: 1.0.3705.209
'
'
     Changes to this file may cause incorrect behavior and will be lost if 
'
     the code is regenerated.
'
 </autogenerated>
'
------------------------------------------------------------------------------

 

因为对XML了解不深,查找一些资料才发现原来portalCfg.vb文件根本不用手写,用生成就可以了,无论是xml或config文件都可。
随便找简单的几行代码先试试
建立一个sample.xml 代码如下

<? xml version="1.0" encoding="utf-8"  ?>  
< SiteConfiguration >
    
< Module  ModuleId ="1"  ModuleTitle ="快速連結"  EditRoles ="Admins;"  ModuleDefId ="8"  PaneName ="LeftPane"  CacheTimeout ="0"  ModuleOrder ="1"  ShowMobile ="false"   />
    
< Module  ModuleId ="2"  ModuleTitle ="歡迎使用入口網站入門套件 (Portal Starter Kit)"  EditRoles ="Admins;"  ModuleDefId ="5"  PaneName ="ContentPane"  CacheTimeout ="0"  ModuleOrder ="1"  ShowMobile ="true"   />
</ SiteConfiguration >

然后在VS2003 里面 按mouse右键 --〉生成架构 你会发现项目中会多出一个 sample.xsd的文件而且你的portalCfg.xml的文件也变成如下
<? xml version="1.0" encoding="utf-8" ?>
< SiteConfiguration  xmlns ="http://tempuri.org/sample.xsd" >
    
< Module  ModuleId ="1"  ModuleTitle ="快速連結"  EditRoles ="Admins;"  ModuleDefId ="8"  PaneName ="LeftPane"  CacheTimeout ="0"  ModuleOrder ="1"  ShowMobile ="false"   />
    
< Module  ModuleId ="2"  ModuleTitle ="歡迎使用入口網站入門套件 (Portal Starter Kit)"  EditRoles ="Admins;"  ModuleDefId ="5"  PaneName ="ContentPane"  CacheTimeout ="0"  ModuleOrder ="1"  ShowMobile ="true"   />
</ SiteConfiguration >

portal.xsd的代码
<? xml version="1.0" ?>
< xs:schema  id ="SiteConfiguration"  targetNamespace ="http://tempuri.org/sample.xsd"  xmlns:mstns ="http://tempuri.org/sample.xsd"  xmlns ="http://tempuri.org/sample.xsd"  xmlns:xs ="http://www.w3.org/2001/XMLSchema"  xmlns:msdata ="urn:schemas-microsoft-com:xml-msdata"  attributeFormDefault ="qualified"  elementFormDefault ="qualified" >
  
< xs:element  name ="SiteConfiguration"  msdata:IsDataSet ="true"  msdata:Locale ="zh-CN"  msdata:EnforceConstraints ="False" >
    
< xs:complexType >
      
< xs:choice  maxOccurs ="unbounded" >
        
< xs:element  name ="Module" >
          
< xs:complexType >
            
< xs:attribute  name ="ModuleId"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="ModuleTitle"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="EditRoles"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="ModuleDefId"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="PaneName"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="CacheTimeout"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="ModuleOrder"  form ="unqualified"  type ="xs:string"   />
            
< xs:attribute  name ="ShowMobile"  form ="unqualified"  type ="xs:string"   />
          
</ xs:complexType >
        
</ xs:element >
      
</ xs:choice >
    
</ xs:complexType >
  
</ xs:element >
</ xs:schema >

然后打开sample.xsd文件 --〉在