loading from xml file

560 views Asked by At

i am trying loading and saving data by Robert Harvey code in this topic. i can save. but load process is not success full.

i have tried :

var list = XmlHelper.FromXmlFile<List<Item>>(@"c:\folder\file.xml");

i did not find the correct namespase for Item

var list = XmlHelper.FromXmlFile<List<Array>>(@"c:\folder\file.xml");
{"Object reference not set to an instance of an object."}
var list = XmlHelper.FromXmlFile<List<ArrayList>>(@"c:\folder\file.xml");
{"<ArrayOfAnyType xmlns=''> was not expected."}
var list = XmlHelper.FromXmlFile<List<Double>>(@"c:\folder\file.xml");
{"<ArrayOfAnyType xmlns=''> was not expected."}

but all of them have error which listed below them.

i want to retrieve those number in form of arraylist or double[];

the XML content : enter image description here

2

There are 2 answers

0
SKull On BEST ANSWER

First Load the Document:

var doc = XDocument.Load("c:\somefile.xml");

Then you can access the Elements with

XElement xe = doc.Element("Name of the Element");

If you got more than one Element with the same name you can get them with:

IEnumerable<XElement> xe = doc.Elements("Name of the Element");

You can Access Attributes kind of similar:

XAttribute xa = doc.Attribute("Name of the Attribute");

and

IEnumerable<XAttribute> xa = doc.Attributes("name");

don't forget to always do null checks.

I hope this helps.

6
Neel On

for loading the data from xml file use the below process if you are using c#

XElement xelement = XElement.Load("..\\..\\XML1.xml");