如何根据输入属性值获取属性值。请帮忙吧。提前致谢 [英] How to get attribute value based on input attribute value. Please help its very urgent. thanks in advance

查看:106
本文介绍了如何根据输入属性值获取属性值。请帮忙吧。提前致谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml文件,其中包含以下数据,我需要给出Name属性并需要获取Heirarchy属性值。

i have one xml file which have below data, i need to give Name attribute and need to get Heirarchy attribute value.

请给我c#代码(linq) to xml 或其他方法)

please give me c# code for this(linq to xml  or other approach)

例如:

输入:  LoginUserName

input: LoginUserName

输出:  LogInWindow,textBox_UserName

output: LogInWindow,textBox_UserName

输入:  PatientCreateName

input: PatientCreateName

输出:  PatienceLogInWindow, textBox_UserName

output: PatienceLogInWindow,textBox_UserName




推荐答案

希望这会有所帮助..

Hope this helps..

    XDocument objDoc = XDocument.Load(@"C:\temp\data.xml");
            var input = "LoginUserName";
            //do needed exception handling for null
            XElement query = objDoc.Descendants().Attributes().Where(x => x.Value == input).ElementAt(0).Parent;
            Console.WriteLine(" {0} ", query.Attribute("Heirarchy").Value);


这篇关于如何根据输入属性值获取属性值。请帮忙吧。提前致谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆