我正在尝试实现 IXmlSerializable。我的类实现了可序列化并编写了一个字符串。我希望能够使用 XsdDataContractExporter(标准模式)导出对象图模式。
该类序列化为一个简单的 xml。
<Urn ns='http://palantir.co.za/urn'>somestring</Urn>
我的GetSchema实现,对应XmlSchemaProvider属性如下。
我需要能够生成和导出模式。
public static XmlQualifiedName GetSchema(XmlSchemaSet xs)
{
string ns = "http://palantir.co.za/urn";
if (xs.Schemas("http://palantir.co.za/urn").Count != 0)
return new XmlQualifiedName("Urn", ns); // tried many.
XmlSchema schema = new XmlSchema();
schema.Namespaces.Add("xs", XmlSchema.Namespace);
schema.Namespaces.Add("Urn", ns); // tried many prefixes.
schema.ElementFormDefault = XmlSchemaForm.Qualified;
schema.Items.Add(
new XmlSchemaElement() {
Name = "Urn",
SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName
});
schema.TargetNamespace = ns;
xs.Add(schema);
//xs.Compile();
return new XmlQualifiedName("Urn", schema.TargetNamespace);
}
我收到以下错误:
未声明http://www.w3.org/2001/XMLSchema:schema元素。当我尝试导出架构时。