2012-01-22 7 views
0

私はxmlファイルを持っています.iはc#クラスにシリアル化する必要があります。C#Xmlのシリアル化の問題

<Configs> 
    <Services> 
    <Path> 
     <Url>test</Url> 
     <ID>1234</ID> 
    </Path> 
     <Path> 
     <Url>java</Url> 
     <ID>1234</ID> 
    </Path> 
    </Services> 
    <Certification> 
     <name>Mark</name> 
     <name>Peter</name> 
    </Certification> 
    </Configs> 
    </Configuration> 

私は次のクラスを書かれているクラス

にこれをシリアル化する必要があります。

public class Configuration 
     { 
      public Certification Configs { get; set; } 
      public Path[] Services { get; set; } 
     } 

     public class Certification 
     { 
      [XmlArray("Certification")] 
      [XmlArrayItem("name")] 
      public string[] name { get; set; } 

      } 

     public class Path 
     { 
      public string Url { get; set; } 
      public string ID { get; set; } 
     } 

私はCertificationクラスの値とその値を取得しています。 私はコンフィギュレーションのためのオブジェクトを作成し、これはに取り組んでいる

foreach (string Name in obj.Configs.name) 
{ 
} 

をループ。

しかし、私はサービスの価値を得ていません。 obj.services

Foreach (Path serviceUrl in obj.Services) 
    { 
    } 

obj.Servicesにnullを得ることが

どのようにパス内のURLとIDノードの値を取得するにはnullである これを動作していませんか?

答えて

2

あなたServices配列が間違ったクラスである

感謝。ルートクラスのConfigsプロパティの内側にある必要があります。

public class Configuration 
{ 
    public Certification Configs { get; set; } 
} 

public class Certification 
{ 
    [XmlArray("Certification")] 
    [XmlArrayItem("name")] 
    public string[] name { get; set; } 

    public Path[] Services { get; set; } 
}