<?xml version="1.0" encoding="utf-8" ?>
<NewDataSet>
  <Table>
    <node ID="1" PintName="abc" objectId="87678" FunctionId="1"/>
    <node ID="2" PintName="def" objectId="39392" FunctionId="1"/>
    <node ID="3" PintName="ghi" objectId="996378" FunctionId="2"/>
    <node ID="4" PintName="jkl" objectId="996378" FunctionId="2"/>
    <node ID="5" PintName="mnl" objectId="996378" FunctionId="2"/>
  </Table>
</NewDataSet>我想取出PintName列的所有值放在ArrayList数组中,比如我想取出PointName列的所有值,类似下面代码(但不会写,希望高手帮忙填充)       ArrayList _PointName = new ArrayList();
       foreach (...)
       {
            _PointName.Add(...);
       }然后用的时候是—>_PointName[0].ToString()的值为1,_PointName[1].ToString()的值为2 等等。

解决方案 »

  1.   

     string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
    <NewDataSet>
      <Table>
        <node ID=""1"" PintName=""abc"" objectId=""87678"" FunctionId=""1""/>
        <node ID=""2"" PintName=""def"" objectId=""39392"" FunctionId=""1""/>
        <node ID=""3"" PintName=""ghi"" objectId=""996378"" FunctionId=""2""/>
        <node ID=""4"" PintName=""jkl"" objectId=""996378"" FunctionId=""2""/>
        <node ID=""5"" PintName=""mnl"" objectId=""996378"" FunctionId=""2""/>
      </Table>
    </NewDataSet>";
                XElement xmlPage = XElement.Parse(xml);            var query = from x in xmlPage.Descendants("node")
                            select x.Attribute("PintName").Value;            foreach (var q in query)
                {
                    Console.WriteLine(q);
                }abc
    def
    ghi
    jkl
    mnl
      

  2.   

     XElement xmlPage = XElement.Parse(xml);中的xml是xml文件的地址么?用了之后怎么报错呢XElement xmlPage = XElement.Parse(@"C:\Documents and Settings\user\My Documents\Visual Studio 2010\Projects\XMLDB\XMLFile1.xml");