从XML属性检索值
问题描述:
我想从xml文件过滤使用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文本。
if name =“Size”然后我将它的值添加到大小文本框。
问候
冲
答
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#版本
希望这有助于
答
您可以在表单中使用递归也查找过所有的控制和你的XML应用到它的属性(例如:对于每一种控制类型,你都可以创建特定的类,该类型将被用于该类型 - 你可以使用字典(即controls[control.GetType()].ApplySettings(xml)
)。
对不起,我没有找到chooseingle,它是SelectSingleNode? – Chong 2010-12-22 10:19:13