我有一个类,想要将XML文档反序列化为它:
[XmlRoot(ElementName = "MyType", Namespace = "MyNamespace")]
public class MyClass : MyBase { }
And
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(Namespace = "BaseNamespace")]
[XmlRootAttribute("MyBaseType", Namespace = "BaseNamespace", IsNullable = false)]
[GuidAttribute("8d9586ec-f263-48e2-ad47-53093430bce4")]
public class MyBase { }
当进行反序列化时,我遇到了一个错误,提示“没有找到具有元数据的XML模式文件AAA-Fachschema.xsd”:
XML schema file with metadata not found at AAA-Fachschema.xsd":null
以下是一些简化的Xml代码:
<?xml version="1.0" encoding="utf-8"?>
<!--some comments -->
<q1:MyType xsi:schemaLocation="http://www.adv-online.de/namespaces/adv/gid/6.0 NAS-Operationen.xsd" xmlns:q1="MyNamespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:ogc="http://www.adv-online.de/namespaces/adv/gid/ogc" xmlns:wfs="http://www.adv-online.de/namespaces/adv/gid/wfs" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns="BaseNamespace">
</q1:MyType>
并且代码反序列化:
using (var reader = new XmlReader(theFile, new XmlReaderSettings { ValidationType = ValidationType.None }))
{
var ser = new XmlSerializer(typeof(MyClass));
var o = ser.Deserialize(reader);
}
但我不确定这个Xsd文件在序列化器中设置的位置。
有人知道在序列化器中设置这些信息的位置,或者更简单的方法是如何完全禁用检查吗?
MyBase
是从Xsdhttp://www.adv-online.de/namespaces/adv/gid/6.0 NAS-Operationen.xsd
自动生成的。然而,这是另一个Xsd,而不是错误消息中提到的那个。 - MakePeaceGreatAgain