日期:2014-05-20  浏览次数:20742 次

如何用数组访问html一个项中的所有属性
现有
<Config MachineType="2" Lang="0" OptimizedType="0" PLCFileName="\HardDisk2\MotionLCE\Basic.plc" FirmwareFileName="" IP3="0" IP4="10">


</Config>



需要用一个循环连续读取此项中所有Attribute的值,而不是一条条读取,情歌问大侠指点好方法。

------解决方案--------------------
try...

C# code
            string test = @"<Config MachineType=""2"" Lang=""0"" OptimizedType=""0"" PLCFileName=""\HardDisk2\MotionLCE\Basic.plc"" FirmwareFileName="""" IP3=""0"" IP4=""10"">


</Config>";
            Regex reg = new Regex(@"(?<key>[^\s=]+)=""(?<value>[^""]*)""");
            MatchCollection mc = reg.Matches(test);
            foreach (Match m in mc)
            {
                richTextBox2.Text += "Key: " + m.Groups["key"].Value + "\nValue: " + m.Groups["value"].Value + "\n====================\n";
            }

------解决方案--------------------
C# code
/*---输出---
Key: MachineType
Value: 2
====================
Key: Lang
Value: 0
====================
Key: OptimizedType
Value: 0
====================
Key: PLCFileName
Value: \HardDisk2\MotionLCE\Basic.plc
====================
Key: FirmwareFileName
Value: 
====================
Key: IP3
Value: 0
====================
Key: IP4
Value: 10
====================
*/