3
Xmlフラグメントを逆シリアル化しようとしています。私はほとんどそこにいますが、それは最初の要素が期待できないところでエラーを投げます。次のように流れにおけるXMLの例は次のとおりです。XMLリーダーを使用してXmlフラグメントを逆シリアル化する方法
<Project xmlns="http://schemas.datacontract.org/2004/07/Swissmod.Service.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ClientID>1</ClientID>
<Created>2009-03-16T20:34:57.022167+00:00</Created>
<ID>22</ID>
<LastModified>2009-03-11T20:34:57.022167+00:00</LastModified>
<ProjectDescription>Description here</ProjectDescription>
<ProjectTitle>Poject title</ProjectTitle>
<UserID>5</UserID>
<Version>1234567</Version>
</Project>
私はシリアル化解除するには、次のコードを使用しています:
XmlSerializer serializer = new XmlSerializer(typeof(Project));
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationFlags = XmlSchemaValidationFlags.None;
settings.ValidationType = ValidationType.None;
settings.ConformanceLevel = ConformanceLevel.Auto;
settings.IgnoreProcessingInstructions = true;
settings.NameTable = new NameTable();
settings.NameTable.Add("http://schemas.datacontract.org/2004/07/Swissmod.Service.Model");
XmlReader reader = XmlReader.Create(wresp.GetResponseStream(),settings);
Project p = (Project)serializer.Deserialize(reader);
しかし、上記は、次のエラーがスローされます。
There is an error in XML document (1, 2).
"<Project xmlns='http://schemas.datacontract.org/2004/07/Swissmod.Service.Model'> was not expected."
XMLリーダーを使用してXMLフラグメントを読み取る方法については、誰でも知っていますか?
Lol、thats that !!あなたのお時間をありがとう。その属性を追加すると、それが並べ替えられました。ありがとうございました。 :-) –
XmlRoot属性*で名前空間を指定すると、 'Project'はどうなるでしょうか? – IAbstract