读书人

xml 操作解决方案

发布时间: 2012-08-31 12:55:03 作者: rapoo

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; 

读书人网 >asp.net

热点推荐