簡體   English   中英

如何將字節轉換為 C# 中的 Xsd Schema

[英]How to convert bytes to Xsd Schema in C#

我實際上正在嘗試將字節 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);
 

但上面沒有轉換它。 還有其他方法嗎?

文檔建議您使用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)

但是,這是XmlSchema上的 static 方法,因此您的代碼會變得更像

Stream streamXsdd = new MemoryStream(File.ReadAllBytes(path + "\\input.xsd"));
XmlSchema xsdDoc = XmlSchema.Read(streamXsddd, validationeventhandler);

XmlSchemaSet tempSchemaDocs = new XmlSchemaSet();
tempSchemaDocs.Add(xsdDoc);

可能是您的Read沒有工作是因為您有效地丟棄了結果,因為它返回一個新實例,而不是填充現有實例?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM