如何根据他们的身份获得特定的员工详细信息 [英] How to get the purticular Employee Detail based on their id

查看:80
本文介绍了如何根据他们的身份获得特定的员工详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家



我的XML文件是:



Hi Experts

My XML file is:

<Employees>
                <Employee>

                    <EmployeeId>1</EmployeeId>
                    <EmployeeName>Vijay</EmployeeName>
                    <EmployeePhone>1234567</EmployeePhone>
                    <EmployeeDesc>Manager</EmployeeDesc>
                    <EmployeeSalary>10000</EmployeeSalary>
                    <EmployeeAddress>Delhi</EmployeeAddress>

                </Employee>

                <Employee>

                    <EmployeeId>2</EmployeeId>
                    <EmployeeName>Arun</EmployeeName>
                    <EmployeePhone>876543</EmployeePhone>
                    <EmployeeDesc>AstManager</EmployeeDesc>
                    <EmployeeSalary>8000</EmployeeSalary>
                    <EmployeeAddress>Mumbai</EmployeeAddress>

                </Employee>

                <Employee>

                    <EmployeeId>3</EmployeeId>
                    <EmployeeName>Ram</EmployeeName>
                    <EmployeePhone>0718292</EmployeePhone>
                    <EmployeeDesc>Clerk</EmployeeDesc>
                    <EmployeeSalary>7000</EmployeeSalary>
                    <EmployeeAddress>Chennai</EmployeeAddress>

                </Employee>

</Employees>











这里我只想提取员工的详细信息取决于他们的员工ID



我试过这样的。








Here i want to extract only the employee detail depends on their Employee ID

I have tried like this.

Result have this XML content.

XDocument xdoc = XDocument.Parse(result);

var Emp = from res in xdoc.Descendants()
                       where res.Name == "Employee"
                       select res;







但在这里我得到了所有员工的详细信息。但我想要特定的员工细节。但我无法得到特定的员工细节。

请帮我如何根据他们的ID获取特定的员工细节?




But here i get all the employee details. But i want particular employee details. But i can not get the particular employee detail.
Please help me how to get the particular employee detail based on their ID??

推荐答案

我不是专家,但希望这有助于你:查找具有特定属性的元素 [ ^ ]
I am no expert, but hope this helps you: Find an Element with a Specific Attribute[^]


尝试这样..



try like this..

var Emp = from res in xdoc.Descendants("Employee")
                  where (string) res.Element("EmployeeId")  =="1"
                 select res;


这篇关于如何根据他们的身份获得特定的员工详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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