如何读取XML中的所有属性值以及如何将这些值存储在列表集合中?预先感谢。 [英] How to read all attributes values in XML and how to store that values in list collections? Thank in advance.
本文介绍了如何读取XML中的所有属性值以及如何将这些值存储在列表集合中?预先感谢。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它给出了错误..无法隐式地将字符串转换为System.Collections.Generic
我尝试过:
这是我的XML代码:
it gives error..Cannot implicitly convert string to System.Collections.Generic
What I have tried:
this is my XML code:
<Students>
<Student>
<StudentName>sa</StudentName>
<ID>1</ID>
<CSharp>5</CSharp>
<Java>9</Java>
<Rdbms>5</Rdbms>
<JavaScript>62</JavaScript>
<Jquery>42</Jquery>
<Networking>54</Networking>
<Total>177</Total>
</Student>
<Student>
<StudentName>san</StudentName>
<ID>2</ID>
<CSharp>5</CSharp>
<Java>9</Java>
<Rdbms>5</Rdbms>
<JavaScript>62</JavaScript>
<Jquery>42</Jquery>
<Networking>54</Networking>
<Total>177</Total>
</Student>
这就是我的尝试
this is what I tried
student = (xNode.Attributes["StudentName"].Value) + (xNode.Attributes["ID"].Value) + (xNode.Attributes["CSharp"].Value) + (xNode.Attributes["Java"].Value) + (xNode.Attributes["Rdbms"].Value) + (xNode.Attributes[" JavaScript"].Value) + (xNode.Attributes[" Jquery"].Value) + (xNode.Attributes[" Networking"].Value) + (xNode.Attributes[" Total"].Value);
推荐答案
您在该XML片段中没有任何属性。你拥有的是儿童元素。
属性是元素的修饰符:
You don't have any attributes in that XML snippet. What you have are child elements.
Attributes are modifier to an element:
<Student id="1" name="Joe Smith">
<CSharp>5</CSharp>
<Java>9</Java>
<Student>
Student元素有两个属性,id和名称,以及两个子元素,CSharp和Java。
您的代码正在寻找XML中不存在的属性。
The Student element has two attributes, id and name, and two child elements, CSharp and Java.
Your code is looking for attributes in your XML that don't exist.
这篇关于如何读取XML中的所有属性值以及如何将这些值存储在列表集合中?预先感谢。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文