私はこの問題の回答をすべて読みましたが、私の場合はすべて解決しましたが(良い解決策ですが)、xsd.exeから派生したxsd.exeからXMLをデシリアライズする際にエラーが発生しました。
私はそれの関連する部分を投稿しますので、それは7000+ラインのクラスを生成し
Xsd.exeでは/ C neworder.xsd
と私のXSDファイルからのAC#クラスを作成しました。ほんの少しの抜粋です
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Xml;
using System.Collections.Generic;
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34234")]
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.foo.com/schemas/w/v1.0")]
[System.Xml.Serialization.XmlRootAttribute("new-order", Namespace = "http://www.foo.com/schemas/w/v1.0")]
public partial class neworder
{
private List<customertype> customersField;
private string suppliercodeField;
private string versionField;
private static System.Xml.Serialization.XmlSerializer serializer;
public neworder()
{
this.customersField = new List<customertype>();
}
[System.Xml.Serialization.XmlArrayAttribute(Order = 0)]
[System.Xml.Serialization.XmlArrayItemAttribute("customer",IsNullable = false)]
public List<customertype> customers
{
get
{
return this.customersField;
}
set
{
this.customersField = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute("supplier-code")]
public string suppliercode
{
get
{
return this.suppliercodeField;
}
set
{
this.suppliercodeField = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute("version")]
public string version
{
get
{
return this.versionField;
}
set
{
this.versionField = value;
}
}
private static System.Xml.Serialization.XmlSerializer Serializer
{
get
{
if ((serializer == null))
{
serializer = new System.Xml.Serialization.XmlSerializer(typeof(neworder));
}
return serializer;
}
}
public static neworder Deserialize(string xml)
{
System.IO.StringReader stringReader = null;
try
{
stringReader = new System.IO.StringReader(xml);
return ((neworder)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader))));
}
finally
{
if ((stringReader != null))
{
stringReader.Dispose();
}
}
}
私はこれを解決しますならば、私は残りの部分を解決することができるように感じるように、残りは今それは重要ではありません。
これは私が私が手にエラーが悪名高いです以下
XmlSerializer ser = new XmlSerializer(typeof(neworder));
neworder feed = (neworder)ser.Deserialize(new FileStream(filePath, FileMode.Open)) ;
でそれをデシリアライズしよう
<new-order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.foo.com/schema/w/v1.0" version="1.0" supplier-code="FAKECODE" schemaLocation="http://www.foo.com/schemas/w/v1.0/TransmissionEnvelope.xsd">
<customers>
<customer w-number="123456" customer-number="12345-12345">
<client-info>
<client-name>John Doe</client-name>
<w-id>433348</w-id>
</client-info>
<transferee-name>
<first>John</first>
<last>Doe</last>
</transferee-name>
<spouse-name>
<first />
<last />
</spouse-name>
<o-address>
<street1>123 Fake st</street1>
<city>Fakeville</city>
<state>CA</state>
<postal-code>90210</postal-code>
<country>USA</country>
</o-address>
<d-address>
<street1 />
<city>harbour</city>
<state>VA</state>
<postal-code>55555</postal-code>
<country>USA</country>
</d-address>
<contact-info>
<phone>
<phone-type>CELL</phone-type>
<phone-number>555-555-5555</phone-number>
</phone>
<phone>
<phone-type>HOME</phone-type>
<phone-number>555-555-5555</phone-number>
</phone>
<phone>
<phone-type>WORK</phone-type>
<phone-number />
</phone>
<email>[email protected]</email>
<comments>Just any comments here</comments>
</contact-info>
</customer>
</customers>
</new-order>
XMLファイルの先頭部分である:
ありXML文書のエラーです(1,2)。 http://www.foo.com/schema/w/v1.0 '>は期待されていませんでした。
私は、上記のことを行う属性XMLROOTとしてルートノートを確認することについて何度も何度も読んできました。そしてそれには正しい名前空間があります。
XmlRootAttributeをXmlRootに変更しようとしました。何もない。 私は名前空間を削除して、クラスを再実行しようとしましたが、何もしませんでした。
すべてが正当だと思われるので、ここで間違っているかもしれないことに私の脳を壊す。
スキーマとXMLファイル。 – Aybe
完全なxmlファイルを投稿できますか(おそらく1つは削除されています)? 'xmlns =" http://www.foo.com/schemas/w/v1.0 "'のように 'schema'に' s'を追加して例外を止めることができましたが、私は知らない「xmlファイル」でテストすることによって問題が発生した場合は、「」要素のみ*です。 –
Quantic
XMLファイルが追加されました。 ** my **スキーマではないので、スキーマを投稿したくありません。 私が一時的な回避策としてやったのは(私たちはすべてのテストドキュメントを表示するかどうかを見ています)、私はそれからクラスを作成したテストドキュメントのxsd.exeを使ってXSDファイルを作成しました。これは、1つのXML文書で動作しますが、私は複数試みています。 私は行きたいとは思いませんが、まあまあです。 – reindeerKurt