wpf操作xml文件

复制代码
using  System.Xml.Linq;

public  XElement Config  =  XElement.Load( @" config/set.xml " );

// 读取节点中全部数据 -读取Map节点
GetTreeNode(Config, " Map " " Sign " " 2 " ); //返回一个XElement类型


// 读取节点LevelUp,并返回LevelUp中所有Experience的节点
GetTreeNode(GameTool.SystemConfig,  " LevelUp " ).Elements( " Experience " )  //返回一个IEnumerable<XElement> 的类型

        
///   <summary>
        
///  获取XML文件树节点
        
///   </summary>
        
///   <param name="xml"> XML文件载体 </param>
        
///   <param name="mainnode"> 要查找的主节点 </param>
        
///   <param name="attribute"> 主节点条件属性名 </param>
        
///   <param name="value"> 主节点条件属性值 </param>
        
///   <returns> 以该主节点为根的XElement </returns>
         public  XElement GetTreeNode(XElement XML,  string  newroot,  string  attribute,  string  value)
        {
            
return  XML.DescendantsAndSelf(newroot).Single(X  =>  X.Attribute(attribute).Value  ==  value);
        }

        
///   <summary>
        
///  获取XML文件树节点
        
///   </summary>
        
///   <param name="XML"> XML文件载体 </param>
        
///   <param name="newroot"> 要查找的独立节点 </param>
        
///   <returns> 独立节点XElement </returns>
         public  XElement GetTreeNode(XElement XML,  string  newroot)
        {
            
return  XML.DescendantsAndSelf(newroot).Single();
        }
复制代码

xml文件为:

复制代码
< Config >
 
< Maps >
  
< Map  Sign ="2" >
   
< Surface  Src ="Map\0\0.jpg"  Width ="1750"  Height ="1440"  X ="0"  Y ="0" ></ Surface >
   
< Mask  Src ="Map\0\0.png"  Width ="55"  Height ="73"  X ="1040"  Y ="179"  CenterY ="73"  Opacity ="0.7" ></ Mask >
   
< Mask  Src ="Map\0\1.png"  Width ="202"  Height ="395"  X ="793"  Y ="612"  CenterY ="395"  Opacity ="0.7" ></ Mask >
   
< Spirits >
    
< Monster  Name ="Magicer006"  Faction ="倾城之恋"  Clan ="美丽呀"  SName ="倒影在心房"  VLife ="500"  VSpell ="100"  VEnergy ="0"  VEnergyMax ="0"  VLevel ="2"  VExperience ="0"  Power ="60"  Agile ="45"  Physique ="40"  Wisdom ="30"  Lucky ="5"  FaceSign ="100"  PKmode ="1"  PKValue ="-7"  FrameRange0 ="10"  FrameRange1 ="12"  FrameRange2 ="11"  FrameRange3 ="13"  FrameRange4 ="15"  HoldWidth ="2"  HoldHeight ="1"  EfficaciousSection0 ="60"  EfficaciousSection1 ="95"  EfficaciousSection2 ="40"  EfficaciousSection3 ="130"  SingleWidth ="150"  SingleHeight ="150"  TotalWidth ="9150"  TotalHeight ="1200"  Equipment0 ="100"  Equipment1 ="0"  CenterX ="75"  CenterY ="125"  X ="700"  Y ="700"  Direction ="4"  Speed ="120"  LifeTotalWidth ="45" ></ Monster >
   
</ Spirits >
  
</ Map >

< Argument >
    
< LevelUp >
   
< Experience  Level ="0"  Value ="0"   />
   
< Experience  Level ="1"  Value ="0"   />
   
< Experience  Level ="2"  Value ="400"   />
   
< Experience  Level ="3"  Value ="1280"   />
   
< Experience  Level ="4"  Value ="2720"   />
   
< Experience  Level ="5"  Value ="4800"   />
   
< Experience  Level ="6"  Value ="7600"   />
  
</ LevelUp >
 
</ Argument >

</ Config >
复制代码

猜你喜欢

转载自blog.csdn.net/ghevinn/article/details/48026927
今日推荐