[英]How to convert bytes to Xsd Schema in C#
i am actually trying to convert the bytes stream Xsd file into Xsd Schema but was unable to do it through the below code我实际上正在尝试将字节 stream Xsd 文件转换为 Xsd 模式,但无法通过以下代码完成
Stream streamXsdd = new MemoryStream(File.ReadAllBytes(path + "\\input.xsd"));
XmlSchema xsdDoc = new XmlSchema();
xsdDoc.Write(streamXsdd); OR Read(streamXsdd,validationeventhandler);
// i thought the above are used for conversion but they are not.
XmlSchemaSet tempSchemaDocs = new XmlSchemaSet();
tempSchemaDocs.Add(xsdDoc);
but above does not convert it.但上面没有转换它。 Is there any other way to do it?
还有其他方法吗?
The docs suggest you would want to use XmlSchema.Read
.文档建议您使用
XmlSchema.Read
。
https://learn.microsoft.com/en-us/do.net/api/system.xml.schema.xmlschema.read?view.net-6.0#system-xml-schema-xmlschema-read(system-io-stream-system-xml-schema-validationeventhandler) https://learn.microsoft.com/en-us/do.net/api/system.xml.schema.xmlschema.read?view.net-6.0#system-xml-schema-xmlschema-read(system-io- stream-system-xml-schema-validationeventhandler)
However this is a static method on XmlSchema
so your code would change to be more like但是,这是
XmlSchema
上的 static 方法,因此您的代码会变得更像
Stream streamXsdd = new MemoryStream(File.ReadAllBytes(path + "\\input.xsd"));
XmlSchema xsdDoc = XmlSchema.Read(streamXsddd, validationeventhandler);
XmlSchemaSet tempSchemaDocs = new XmlSchemaSet();
tempSchemaDocs.Add(xsdDoc);
Could it be that your Read
wasn't working because you were effectively discarding the result, as it returns a new instance, rather than populating an existing one?可能是您的
Read
没有工作是因为您有效地丢弃了结果,因为它返回一个新实例,而不是填充现有实例?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.