<?xml version="1.0" encoding="utf-8" ?> <UIConfig Count="1"> <workflow name="OilInbound"> <activity name="Started"> <Input> <Page></Page> <Method></Method> </Input> <Brief> <Page>OilInboundTaskDetail</Page> <Method>GetTaskDetailModel</Method> </Brief> <Detail> <Page>OilInboundTaskDetail</Page> <Method>GetTaskDetailModel</Method> </Detail> <DisplayName>任务创建</DisplayName> </activity> <activity name="OilCompositionAnalysis"> <Input> <Page>OilAnalyzingDataInput</Page> <Method>GetOilAnalyzingDataInputModel</Method> </Input> <Brief> <Page>OilAnalyzingDataBrief</Page> <Method>GetOilAnalyzingDataBriefModel</Method> </Brief> <Detail> <Page>OilAnalyzingDataDetail</Page> <Method>GetOilAnalyzingDataDetailModel</Method> </Detail> <DisplayName>化验</DisplayName> </activity> </workflow> </UIConfig> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Xml.Linq; using System.Xml; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { XElement doc = XElement.Load("..//..//data-config.xml");//根元素 string sss = getStr(doc, "OilInbound", "Started", "Input", "Page"); Console.WriteLine(sss); Console.ReadKey(); } //如果当前元素的子元素只有一个,可以直接用.Element("elementName")来得到,如果是多个子元素就用Elements("elementName")得到 private static string getStr(XElement doc,string workflowName,string stepName,string typeName,string pageMethod) { var strEle = from workflow in doc.Elements("workflow") where (string)workflow.Attribute("name") == workflowName select new{ str = workflow.Elements("activity").TakeWhile(x => (string)x.Attribute("name") == stepName).First().Element(typeName).Element(pageMethod).Value }; return strEle.First().str; } } }