我想通过xml属性从xml文件过滤中获取一些值。 我的xml格式如下所示。
<Object type="System.Windows.Forms.TextBox">
<Property name="Name">RadioButton1</Property>
<Property name="Size">86, 24</Property>
<Property name="Text">RadioButton1</Property>
<Property name="Location">175, 126</Property>
</Object>
例如,
如果name =“Name”,那么我将其值添加到名称文本框。
如果name =“Size”,那么我将其值添加到文本框大小。
问候
冲
答案 0 :(得分:2)
xmlDocument doc = new xmlDocument()
doc.LaodXml(xmlString);
TextBox1.Text = doc.SelectSingle("Object/Property[@name='name']").attributes[0].value == "name"?
doc.SelectSingle("Object/Property[@name='Name']").InnerText: string.Empty;
//do the same for the next attribute you want
这是一个C#版本
希望这有帮助
答案 1 :(得分:1)
你可以使用递归来查找表单中的所有控件,并将xml应用于其属性(例如:对于每种控件类型,您可以创建将为该类型采用的特定类 - 您可以使用字典(即controls[control.GetType()].ApplySettings(xml)
)。