特定の XML ファイルを単一のオブジェクトにデシリアライズしていますが、これは正常に機能しています。ただし、別のオブジェクトに逆シリアル化する必要がある属性を追加するように XML ファイルを調整する必要があるため、1 つの指定された xml ファイルから 2 つのオブジェクトを設定できますが、これは 1 回の操作で可能ですか?
ここに私の現在のコードとXMLがあります:
XML 現在の状態:
<NameCollection>
<Names>
<Name>
<description></description>
<Name>
<Name>
<description></description>
<Name>
</Names>
</NameCollection>
XML 私が望むように:
<NameCollection>
<GenericName></GenericName>
<GenericDescription></GenericDescription>
<Names>
<Name>
<description></description>
<Name>
<Name>
<description></description>
<Name>
</Names>
</NameCollection>
コード:
NameCollection commands;
XMLSerializer serializer = new XMLSerializer(typeof(NameCollection));
StreamReader streamReader = new StreamReader(xmlpath);
commands = (NameCollection)serializer.Derserialize(streamreader);
streamReader.Close();
そして現在のオブジェクト:
[Serializable()]
public class TestCommand
{
public string description{get;set;}
}
[Serializable()]
[XmlRoot("NameCollection")]
public class NameCollection
{
[XmlArray("Commands")]
[XmlArrayItem("Command", typeof(TestCommand))]
public TestCommand[] TestCommand {get;set;}
}
次に、GenericName および GenericDescription 属性を別の別のオブジェクトに追加したいと考えています。