首页 新闻 搜索 专区 学院

linq2xml

0
[已关闭问题]
<P>&lt;?xml version="1.0" encoding="utf-8" ?&gt;<BR>&lt;configuration&gt;<BR>&nbsp; &lt;facilities&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;facility<BR>&nbsp;&nbsp;&nbsp;id="event.wiring"<BR>&nbsp;&nbsp;&nbsp;type="Castle.Facilities.EventWiring.EventWiringFacility, Castle.MicroKernel" /&gt;<BR>&nbsp; &lt;/facilities&gt;<BR>&nbsp; &lt;components&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;component<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT color=#008000>id="123"<BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="FlowEngine.SimplePublisher, FlowEngine"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;subscribers&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;subscriber id="listener.component"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event="Event"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handler="OnPublishEvent"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;subscriber id="listener.component2"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;event="Event"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handler="OnPublishEvent2"/&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/subscribers&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;parameters&gt;<BR><FONT color=#008000>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;parameter name="A" key="guid_A"&gt;&lt;/parameter&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;parameter name="B" key="guid_B"&gt;&lt;/parameter&gt;</FONT><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/parameters&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;/component&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;component<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id="listener.component"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="FlowEngine.SimpleListener, FlowEngine" /&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;component<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id="listener.component2"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="FlowEngine.SimpleListener2, FlowEngine" /&gt;<BR>&nbsp; &lt;/components&gt;<BR>&lt;/configuration&gt;</P> <P>找出compoment的属性id=3的特定Component节点下&lt;parameters&gt;节点下所有的&lt;parameter&gt;节点中的内容,并以Dictionary&lt;string,string&gt;的形式返回,使用&lt;parameter&gt;节点中的name属性的值做为键,使用&lt;parameter&gt;节点中的key属性的值做为键值,请指点下</P>
lexus的主页 lexus | 初学一级 | 园豆:0
提问于:2008-06-24 14:33
< >
分享
其他回答(1)
0
static private Dictionary<String, String> GetConfiguration(String fileName, String id) { Dictionary<String, String> dict = new Dictionary<string, string>(); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load("configuration.xml"); System.Xml.XmlNodeList parameters = doc.SelectNodes(String.Format( "//component[@id='{0}']/parameters/parameter", id)); foreach (System.Xml.XmlNode parameter in parameters) { try { dict.Add(parameter.Attributes["name"].Value, parameter.Attributes["key"].Value); } catch { } } return dict; }
eaglet | 园豆:17119 (专家六级) | 2008-06-25 07:52
0
dim xml = ...' 那个XML dim component =(from x in xml...<component> _ where x@id="3").First dim parameters =(from parameter in componet...<parameter> _ select parameter@name,parameter@key).ToDictionary(Of String)(Function(x) (x.name))
G yc {Son of VB.NET} | 园豆:2006 (老鸟四级) | 2008-06-25 13:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册