最简单的读取XML与属性的方法 [英] Easiest way to read XML with attributes

查看:242
本文介绍了最简单的读取XML与属性的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件,我想读(与XML atrributes)。的结构不发生变化,但内容确实

I have a XML file I would like to read (with xml atrributes). The structure doesn't change, but the content does.

示例XML: http://www.yr.no /place/Norway/Oslo/Oslo/Oslo/forecast.xml (URL必须被复制和手动粘贴到地址栏,或者你会得到一个404似乎。)

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.)

我无法使用此code(以及使用XSD.EXE)从中做出XSD:

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");

结果是:

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

现在,想象一下我懒最重要的是,并没有觉得像手工花我整个晚上XML映射到我的对象。我想生成管理code对象为我,所以我可以很容易地读取数据。

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.

我有什么选择?

...如果有人知道,什么是XSD转换错误信息是什么意思?

...and if anyone knows, what does the XSD convert error message mean?

推荐答案

要回答你有关XSD.EXE错误最后一点,它是有问题的多的位置的元素。如果您保存XML和重命名第一个的位置的元素为类似的 baselocation 的那么它会转换成好的。

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.

您可以然后就可以手动修改XSD或生成的类来处理这个问题。

You may then be able to manually amend the xsd or generated classes to handle this.

这篇关于最简单的读取XML与属性的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆