wpf操作xml文件

前端之家收集整理的这篇文章主要介绍了wpf操作xml文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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();
}
@H_293_301@

@H_293_301@xml文件为:

@H_293_301@

< 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 >
原文链接:https://www.f2er.com/xml/296235.html

猜你在找的XML相关文章