<?xml version="1.0" ?>
<aliasSection>
<aliases>
<clear />
<add
name="MAIN"
server="JAG8MTO\SQLEXPRESS"
database="RMain"
trustedConnection="false" />
<add
name="DEMO"
server="JAG8MTO\SQLEXPRESS"
database="RDemo"
trustedConnection="false" />
</aliases>
</aliasSection>
在上面的XML文档,我需要寻找一个别名,然后返回服务器和数据库属性。
这是我第一次使用xml文档,而且我很难把它放在头上。
到目前为止,我有这个,我可以找到别名部分,但我不知所措必须从这里开始。
public void Read(string fileName)
{
XDocument doc = XDocument.Load(fileName);
foreach (XElement el in doc.Root.Elements())
{
foreach (XAttribute attr in el.Attributes())
if (attr.ToString() == "aliases")
{
foreach (XElement element in el.Elements())
listBox1.Items.Add(element.Name + " " + element.Value);
foreach (XAttribute attrib in el.Attributes())
listBox1.Items.Add(attrib.Value);
}
}
}
'aliases'的元素,而不是属性 – Fabio