Last post Jul 23, 2015 04:15 AM by creiglee
Jul 20, 2015 03:42 AM|sudip_inn|LINK
My xml data look like below which is saved in xml file called Data.xml :
<?xml version="1.0" encoding="utf-8"?>
<ShipName>Vins et alcools Chevalier</ShipName>
<ShipAddress>59 rue de l'Abbaye</ShipAddress>
now tell me how could i read data in loop for each order one by one. is there any way to use order by clause. if i need to load data by OrderID ASC or DESC then what to write the code. thanks
Jul 20, 2015 05:01 AM|PaulTheSmith|LINK
What code do you have so far? Where are you stuck? Do you have an error that you don't understand?
Jul 21, 2015 04:21 AM|Candy Zhou|LINK
According your code and description, you want to use XmlReader to reader data. So, you can refer to the following link:
Also, you want to load data by OrderID ASC or DESC. We know XmlReader only have read property, we cannot sort directly. I suggest you can use XmlReader to get xml data, then save data to the database or list,finally sort the data.
I hope that will help you.
Jul 21, 2015 05:43 AM|Caillen Zhong|LINK
Try Linq to XML, it's pretty easy to query the elements of the XML document with Linq expression. The orderby statement is just like the orderby keyword in SQL.
For example, to order these "Orders" elements by the "OrderID" property, try this code snippet:
XDocument doc = XDocument.Load("test.xml");
var orderList = from order in doc.Descendants("Orders")
orderby Convert.ToInt32(order.Element("OrderID").Value) descending
foreach (var o in orderList)
To learn more information about Linq To XML, see the documentation here:
LINQ to XML Overview
Jul 23, 2015 04:15 AM|creiglee|LINK
XmlReader xReader = XmlReader.Create(new StringReader(xmlNode));
listBox1.Items.Add("<" + xReader.Name + ">");
You can read XML in some more ways.........Read XML