积极答复者
Xml File To Arraylist in(C#)How?

问题
-
i need some one to make me a demo code that show me
how can i convert xml file to arraylist in c# the xml file structur is
<?xml version="1.0" encoding="utf-8"?>
<Configs>
<Config StoreName="Tag1">
<StoreTime>123</StoreTime>
<StoreMaxCount>123</StoreMaxCount>
<StoreCondition>123</StoreCondition>
</Config>
<Config StoreName="Tag2">
<StoreTime>2222</StoreTime>
<StoreMaxCount>3333</StoreMaxCount>
<StoreCondition>4444</StoreCondition>
</Config>
</Configs>Thank you!
答案
-
Hi Richard.Mr,
For I am not sure what kind of your arraylist you want,so I write a sample for you about
how to read the data from your xml file:
XElement ex = XElement.Load(Server.MapPath("XMLFile8.xml")); IEnumerable<XElement> q = from ele in ex.Elements("Config") select ele; ArrayList alist = new ArrayList(); // you will get all the value in your Config Nodes foreach (XElement x in q.Elements()) { string val = x.Value; alist.Add(val); }
The code above are using Linq to xml,more details please refer to the link below:
http://msdn.microsoft.com/en-US/us-en/library/bb387098.aspx
Hope it can help you.
Best Regards,
Kevin Shen.
- 已标记为答案 Richard.Mr 2014年7月15日 6:35
全部回复
-
Hi Richard.Mr,
For I am not sure what kind of your arraylist you want,so I write a sample for you about
how to read the data from your xml file:
XElement ex = XElement.Load(Server.MapPath("XMLFile8.xml")); IEnumerable<XElement> q = from ele in ex.Elements("Config") select ele; ArrayList alist = new ArrayList(); // you will get all the value in your Config Nodes foreach (XElement x in q.Elements()) { string val = x.Value; alist.Add(val); }
The code above are using Linq to xml,more details please refer to the link below:
http://msdn.microsoft.com/en-US/us-en/library/bb387098.aspx
Hope it can help you.
Best Regards,
Kevin Shen.
- 已标记为答案 Richard.Mr 2014年7月15日 6:35