创建 XmlSerializer 对象时如何解决此异常?
我在 http://www.w3.org/2001/XMLSchema 下载了 XML Schema 的 XML Schema。 xsd。
然后,我使用 XSD.EXE 从下载的文件创建一个类。我将该类命名为 schema.cs
。
然后我执行了这行代码:
XmlSerializer serializer = new XmlSerializer(typeof(schema));
并收到此错误:
XML 元素“注释”来自 名称空间 'http://www.w3.org/2001/XMLSchema' 是 已存在于当前范围内。
如何在不破坏架构的情况下找到重复的元素并修复它?
I downloaded the XML Schema for XML Schemas at http://www.w3.org/2001/XMLSchema.xsd.
I then used XSD.EXE to create a class from the downloaded file. I called the class schema.cs
.
I then executed this line of code:
XmlSerializer serializer = new XmlSerializer(typeof(schema));
and got this error:
The XML element 'annotation' from
namespace
'http://www.w3.org/2001/XMLSchema' is
already present in the current scope.
How do I find the duplicate element and fix it, without breaking the schema?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为生成的类有缺陷。
我更改了属性以修复第一个错误,但发现了一个新错误。
I think the generated class has flaws.
I changed the attribute to fix the first error but a new error is discovered.
因为注释元素只是注释,所以您可以尝试简单地过滤掉所有这些元素。只需首先将 XML 加载到
XDocument
中并删除所有注释元素。Because the annotate elements are just comments, you could try simply filtering all of these out. Just first load the XML into an
XDocument
and remove all annotate elements.