The easiest way to read XML with attributes

I have an XML file that I would like to read (with xml atrributes). The structure does not change, but the contents do.

XML example: http://www.yr.no/place/Norway/Oslo/Oslo/Oslo/forecast.xml (the URL must be copied and pasted into the address field manually, or you will receive a 404 message).

I cannot make XSD with this code (and using XSD.EXE):

XmlTextReader myXmlTextReader = new XmlTextReader("forecast.xml");
DataSet myDataSet = new DataSet();
myDataSet.ReadXml(myXmlTextReader);
myDataSet.WriteXmlSchema("forecast.xsd");

Results in:

Column name 'name' is defined for different mapping types.

Now imagine that I am lazy on this and don’t want the whole evening to manually map the XML to my objects. I want managed code objects to be created for me, so I can read the data easily.

What are my options?

... - , XSD?

+3
3

Xsd.exe, . xml - baselocation, .

xsd , .

+1

XML-, xml XmlDocument. .

+2

Yes, use Linq. I don't have an example code with me, but this link should be running.

http://www.hookedonlinq.com/LinqToXML5MinuteOVerview.ashx

+2
source

Source: https://habr.com/ru/post/1787769/


All Articles