读取XML文件并返回属性值

时间:2015-07-07 07:47:40

标签: c# xml

我想将AB作为参数发送并检索eds2。

XML文件:Profile.xml

boost::mutex m;
void method(datapacket& data)
{
    boost::mutex::scoped_lock l(m);
    [...]

尝试过如下选项,但没有运气。 foo什么都没回来。请注意,缺少什么。

<?xml version="1.0" encoding="utf-8"?>
<ProfileCollection>
<Profiles>
    <Profile LibId="CD" ProfileId="ed1"/>
    <Profile LibId="AB" ProfileId="ed2"/>
</Profiles>
</ProfileCollection> 

有任何建议尽快吗?请事先提前。

1 个答案:

答案 0 :(得分:0)

除了代码中的xml序列化属性(你真的使用它吗?),有关检索ProfileId的代码可能如下所示:

foo = (from n in xml.XPathSelectElements("ProfileCollection/Profiles/Profile")
       where n.Attribute("LibId").Value == libraryID
       select n.Attribute("ProfileId").Value).FirstOrDefault();