日期:2014-05-17  浏览次数:20486 次

字符串截取成数组的问题
<XML>
<item ID="2" Name="Coxwain" />
<item ID="7" Name="Electrician" />
<item ID="8" Name="High Voltage" />
<item ID="10" Name="HLO" />
<item ID="11" Name="Crane Driver" />
<item ID="12" Name="Rigging/ Slinging" />
</XML>
把上面ITEM标签 里面的ID Name用字符串截取然后用数组保存起来 ID和Name用“|”隔开

这个用正则截取 表达式该怎么写

------解决方案--------------------
C# code
   string xml = @"
              <XML>
                <item ID=""2"" Name=""Coxwain"" />
                <item ID=""7"" Name=""Electrician"" />
                <item ID=""8"" Name=""High Voltage"" />
                <item ID=""10"" Name=""HLO"" />
                <item ID=""11"" Name=""Crane Driver"" />
                <item ID=""12"" Name=""Rigging/ Slinging"" />
              </XML>
          ";
         string [] val= XDocument.Load(new StringReader(xml)).Descendants("item").ToList().Select(c =>   c.Attribute("ID")+"|"+c.Attribute("Name") ).ToArray();