加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

wpf操作xml文件

发布时间:2020-12-16 08:57:58 所属栏目:百科 来源:网络整理
导读:using System.Xml.Linq; public XElementConfig = XElement.Load( @" config/set.xml " ); // 读取节点中全部数据-读取Map节点 GetTreeNode(Config, " Map " , " Sign " , " 2 " ); //返回一个XElement类型 // 读取节点LevelUp,并返回LevelUp中所有Experien
using System.Xml.Linq;

public XElementConfig = 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>
/// <paramname="xml"> XML文件载体 </param>
/// <paramname="mainnode"> 要查找的主节点 </param>
/// <paramname="attribute"> 主节点条件属性名 </param>
/// <paramname="value"> 主节点条件属性值 </param>
/// <returns> 以该主节点为根的XElement </returns>
public XElementGetTreeNode(XElementXML, string newroot, string attribute, string value)
{
return XML.DescendantsAndSelf(newroot).Single(X => X.Attribute(attribute).Value == value);
}

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

xml文件为:

< Config >
< Maps >
< Map Sign ="2" >
< Surface Src ="Map.jpg" Width ="1750" Height ="1440" X ="0" Y ="0" ></ Surface >
< Mask Src ="Map.png" Width ="55" Height ="73" X ="1040" Y ="179" CenterY ="73" Opacity ="0.7" ></ Mask >
< Mask Src ="Map1.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 >

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读