2011-02-04 7 views
1

Visual StudioでXSD.exeユーティリティを使用してVisual Basicクラスを生成しました。 Visual Basicでデータをどのように処理するかの例があるかどうかは不思議でした。 MSDNの例はかなり貧弱です。私がCsharpであっても、コードの例を指摘しても問題ありません。XSDで生成されたクラスを使用してVBでXMLを読み取る例

答えて

0

あなたのXSDから生成されたクラスMyClassがあり、そのクラスに適合するXMLデータを持つファイルがMySample.xmlにあるとすれば、このようなことが起こります(私はVBに慣れていません - これはC#です):

// create the XML serializer class, based on your MyClass definition 
XmlSerializer ser = new XmlSerializer(typeof(MyClass)); 

// create filestream to open & read the existing XML file 
FileStream fstm = new FileStream(@"C:\mysample.xml", FileMode.Open, FileAccess.Read); 

// call deserialize 
var result = ser.Deserialize(fstm); 

// if result is not null, and of the right type - use it! 
MyClass deserializedClass = (result as MyClass); 
if(deserializedClass != null) 
{ 
    // do whatever you want with your new class instance! 
} 

これは役に立ちますか?

関連する問題