I have a XML file I would like to read (with xml atrributes). The structure doesn't change, but the content does.
Sample XML: http://www.yr.no/place/Norway/Oslo/Oslo/Oslo/forecast.xml (The URL must be copied and pasted into address field manually or you'll get a 404 it seems.)
I'm unable to make a XSD from it using 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'm lazy on top of that and don't feel like spending my whole evening manually mapping XML to my objects. I want managed code objects to be generated for me so I can easily read the data.
What are my options?
...and if anyone knows, what does the XSD convert error message mean?
If you are going after XML attributes, then why not just load the xml into a XmlDocument. Then you can access the various nodes and attributes.
To answer your final point about the Xsd.exe error, it's having problems with the multiple location elements. If you save the xml and rename the first location element to something like baselocation then it will convert okay.
You may then be able to manually amend the xsd or generated classes to handle this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With