当前位置: 代码迷 >> ASP.NET >> xml 操作解决方案
  详细解决方案

xml 操作解决方案

热度:2192   发布时间:2013-02-25 00:00:00.0
xml 操作
<?xml version="1.0" encoding="utf-8"?>
<Question>
  <category ProblemCName="求职面试" KeyWord="简历,面试,跳槽,工作机会,礼仪,">
  </category>
  <category ProblemCName="职业规划" KeyWord="职业目标,发展前景,行业趋势,职业定位,晋升,测评,">
  </category>
</Question>


怎么获取第一个 category 中的 KeyWord
己就是: 简历,面试,跳槽,工作机会,礼仪,


因为我写的这个xml第一个category的KeyWord会改变,
我的意思是: 
获取[color=#00FF00]第一个 category 中的 KeyWord[/color]


------解决方案--------------------------------------------------------
C# code
private readonly string path = HttpContext.Current.Server.MapPath("XMLFile1.xml");var doc = XDocument.Load(path);IEnumerable<XElement> query = from a in doc.Elements("Question").Elements("category") where (string)a.Attribute("ProblemCName") == "求职面试" select a;  foreach (XElement item in query)                {                    item.Element("KeyWord").Value ;                                   }
------解决方案--------------------------------------------------------
C# code
XmlDocument xmlDoc = new XmlDocument();        xmlDoc.Load("xmlFile.xml");        string firstKeyword = xmlDoc.DocumentElement.ChildNodes[0].Attributes["KeyWord"].Value;
  相关解决方案