在C#ASP.NET的XML文件中读取节点内的单词 [英] Read word inside the node in XML file in C# ASP.NET

查看:80
本文介绍了在C#ASP.NET的XML文件中读取节点内的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,每一个,

我试着解决这个问题,但是我正在努力解决这个问题

请有人能提出任何想法,我怎么能读到节点在xml文件中并计算它



例如我有这个XML文件



 <  员工 >  
< 员工 >
< 名称 > Adams John < /姓名 >
< 年龄 > 35 < /年龄 >
< 性别 > M < / Gender >
< 薪水 > 65000 < / Salary >
< /员工 >
< < span class =code-leadattribute>员工 >
< 姓名 > Mary J ane < / Name >
< 年龄 > 25 < /年龄 >
< 性别 > F < / Gender >
< 薪水 > 75000 < /薪水 >
< / Employee >
< 员工 >
< 名称 > Jhon William < / Name >
< 年龄 > 30 < /年龄 >
< 性别 > M < / Gender >
< 薪水 > 70000 < < span class =code-leadattribute> / Salary >
< /员工 >
< /员工 >





我需要在这个xml文件中读取性别并计算

所以M的输出为2,F的输出为1

我尝试过:



i尝试计算此xml文件中的节点并使用

SelectNodes(//性别)。Count.ToString();



但我不知道如何读取节点

解决方案

您的XML无效,它会终止Employee而不是Employees。修复它,你的代码应该可以工作。



 <  员工 >  
< < span class =code-leadattribute>员工 >
< 姓名 > Adams John < < span class =code-leadattribute> / Name >
< 年龄 > 35 < < span class =code-leadattribute> /年龄 >
< 性别 > M < /性别 >
< span class =code-keyword>< 薪水 > 65000 < /薪水 >
< span class =code-keyword>< / Employee >
< 员工 >
< 姓名 > 玛丽Jane < /姓名 >
< 年龄 > 25 < /年龄 >
< 性别 > F < / Gender >
< 薪水 > 75000 < /薪水 >
< / Employee >
< 员工 >
< 名称 > Jhon William < /姓名 >
< ; 年龄 > 30 < /年龄 >
< ; 性别 > M < /性别 >
< ; 薪水 > 70000 < /薪水 >
< /员工 >
< /员工 > < /跨度>


hello every one,
Im try to solve this problem but I'm struggling with it
please can anyone suggest any idea about how can I read the the node in xml file and count it

For example I have this XML file

<Employees>
     <Employee>
       <Name>Adams John</Name>
       <Age>35</Age>
       <Gender>M</Gender>
       <Salary>65000</Salary>
     </Employee>
     <Employee>
       <Name>Mary Jane</Name>
       <Age>25</Age>
       <Gender>F</Gender>
       <Salary>75000</Salary>
     </Employee>
     <Employee>
       <Name>Jhon William</Name>
       <Age>30</Age>
       <Gender>M</Gender>
       <Salary>70000</Salary>
     </Employee>
   </Employee>



I need to read the gender in this xml file and count it
so the output will be 2 for M and 1 for F

What I have tried:

i try to count the node in this xml file and it working by using
SelectNodes("//Gender").Count.ToString();

but i have n idea about how to read the node

解决方案

Your XML is invalid, it ends Employee instead of Employees. Fix that and your code should work.

<Employees>
     <Employee>
       <Name>Adams John</Name>
       <Age>35</Age>
       <Gender>M</Gender>
       <Salary>65000</Salary>
     </Employee>
     <Employee>
       <Name>Mary Jane</Name>
       <Age>25</Age>
       <Gender>F</Gender>
       <Salary>75000</Salary>
     </Employee>
     <Employee>
       <Name>Jhon William</Name>
       <Age>30</Age>
       <Gender>M</Gender>
       <Salary>70000</Salary>
     </Employee>
</Employees>


这篇关于在C#ASP.NET的XML文件中读取节点内的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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