xml解析
<?xml version= "1.0 " encoding= "UTF-8 "?>
<AgentGroup>
<AgentItem>
<ConnectionString> Data Source=Server;Initial Catalog=GTI_R;Persist Security Info=True;User ID=sa;Password=1234;Connect Timeout=600 </ConnectionString>
<AgentClass> GTI_RAgent </AgentClass>
<Name> abc </Name>
</AgentItem>
<AgentItem>
<ConnectionString> Data Source=server;Initial Catalog=GTI2;Persist Security Info=True;User ID=sa;Password=1234;Connect Timeout=600 </ConnectionString>
<AgentClass> GTI2Agent </AgentClass>
<Name> efg </Name>
</AgentItem>
</AgentGroup>
帮忙写段C#代码,要循环把AgentItem全部读出来
------解决方案--------------------string strxml = " <?xml version=\ "1.0\ " encoding=\ "UTF-8\ "?> <AgentGroup> <AgentItem> <ConnectionString> Data Source=Server;Initial Catalog=GTI_R;Persist Security Info=True;User ID=sa;Password=1234;Connect Timeout=600 </ConnectionString> <AgentClass> GTI_RAgent </AgentClass> <Name> abc </Name> </AgentItem> <AgentItem> <ConnectionString> Data Source=server;Initial Catalog=GTI2;Persist Security Info=True;User ID=sa;Password=1234;Connect Timeout=600 </ConnectionString> <AgentClass> GTI2Agent </AgentClass> <Name> efg </Name> </AgentItem> </AgentGroup> ";
XmlDocument doc = new XmlDocument();
doc.LoadXml( strxml );
System.Xml.XmlNodeList nodes = doc.SelectNodes( "/AgentGroup/AgentItem ");
foreach( XmlNode node in nodes )
{
System.Diagnostics.Trace.WriteLine( node.Name );
}