2011-09-11 14 views
3

XMLのいずれかの要素にコンテンツが混在する可能性はありますか?stringではなく、混合要素のテキストをカスタムオブジェクトとして逆シリアル化しますか?C#XML混在コンテンツのテキストをカスタムオブジェクトとしてデシリアライズしますか?

私はこれを試してみました:テキスト項目を期待

[XmlText(typeof(textType))] 
    [XmlElement("query", typeof(templateBodyQuery))] 
    [XmlElement("expand", typeof(expandType))] 
    [XmlElement("insert", typeof(expandTypeInsert))] 
    public object[] Items { get; set; } 

textTypeとしてシリアライズされるだろうが、私は'textType' cannot be used as 'xml text'エラーを取得します。あなたがのXmlTextのために非プリミティブ型を使用することはできません

public class textType 
{ 
    [XmlText] 
    public string Value { get; set; } 
} 

答えて

0

これは私のtextTypeクラスです。また、XmlTextとXmlElementsを1つのノードの下に持つことができないので、xmlがどのように構造化されるのか理解できていません。

私は、これはあなたが何をしようとしてあると思う:

デシリアライズ
[XmlElement("textType",typeof(textType))] 
[XmlElement("query", typeof(templateBodyQuery))] 
[XmlElement("expand", typeof(expandType))] 
[XmlElement("insert", typeof(expandTypeInsert))] 
public object[] Items { get; set; } 

<Test> 
    <textType>example</textType> 
    <query>...</query> 
    <expand>...</expand> 
</Test> 

を持つItems配列の開始時にtextTypeオブジェクトを持つクラスTestへ「例」のValue

関連する問題