0
我想实现IXmlSerializable。 我的类实现可串行化并写入一个字符串。我希望能够使用XsdDataContractExporter(标准的)导出对象图模式。IXmlSerializable与有效的XmlSchema(XMLSchema:架构'元素未声明..)
该类序列化为一个简单的xml。
<Urn ns='http://palantir.co.za/urn'>somestring</Urn>
我的对应于XmlSchemaProvider属性的GetSchema实现如下。
我需要能够生成和导出架构。
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);
}
我得到以下错误:
The http://www.w3.org/2001/XMLSchema:schema element is not declared..当我尝试导出模式。
'导出模式':你的意思是当你将它添加到一个XML文件实现? – 2009-11-28 15:21:25