我想將其中包含數據庫對象的xmla文件反序列化爲正確的對象表示形式。 (我不知道它是否應該是一個數據庫)。所以,我做到以下幾點:使用分析管理對象(AMO)將xmla文件反序列化爲對象
Database db = new Database();
XmlTextReader xmlread = new XmlTextReader("input.xmla");
Microsoft.AnalysisServices.Utils.Deserialize(xmlread, db);
xmlread.Close();
,但我得到了以下錯誤:
Unhandled Exception: Microsoft.AnalysisServices.XmlSerializationException: Unexpected root 'Create' (namespace 'http://schemas.microsoft.com/analysisservices/2003/engine') when trying to read 'Microsoft.AnalysisServices.Database'.
at Microsoft.AnalysisServices.DesignXmlReader.ReadRoot (System.Type type) [0x00000] in <filename unknown>:0
at Microsoft.AnalysisServices.DesignXmlReader.DeserializeComponent (IDesignerSerializationManager manager, System.Xml.XmlReader reader, System.Type root) [0x00000] in <filename unknown>:0
at Microsoft.AnalysisServices.JaXmlSerializer.DeserializeComponent (IDesignerSerializationManager manager, System.Xml.XmlReader reader, System.Type root) [0x00000] in <filename unknown>:0
at Microsoft.AnalysisServices.Utils.Deserialize (System.Xml.XmlReader xmlReader, Microsoft.AnalysisServices.MajorObject obj) [0x00000] in <filename unknown>:0
的input.xmla文件看起來是這樣的:
<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
<ObjectDefinition>
<Database xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200">
<ID>100</ID>
<Name>Deserialized</Name>
<Description>Deserialized Description</Description>
</Database>
</ObjectDefinition>
</Create>
我找不到很好的例子。任何幫助將不勝感激。
考慮xml命名空間'http:// schemas.microsoft.com/analyzeservices/2003/engine' –
@ L.B,我對c#,amo和反序列化非常沒有經驗,你能解釋一下嗎? –
對不起,Faruk,我從來沒有使用'Microsoft.AnalysisServices.Utils'但應該有一些方法來設置庫中的命名空間。也許你可以使用'xmlread.NameTable.Add' –