首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

xml 操作解决方案

2012-08-31 
xml 操作?xml version1.0 encodingutf-8?Questioncategory ProblemCName求职面试 KeyWord

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; 

热点排行