2

次に示す C# クラスは、この XML を生成します。

<Standardize><TestString>Some Data</TestString></Standardize>

しかし、私が欲しいのはこれです:

<Standardize>Some Data</Standardize>

つまり、TestString プロパティの内容を XML で表示したいのですが、TestString プロパティを要素としてリストしたくはありません。これを実現するためにいくつかの属性を追加できますか?

   /// <Serialized C# Class/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://test.com/Services/1")]
    public partial class Standardize {


        private string testField;


        [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.None, IsNullable=true, ElementName=null)]
        public string TestString {
            get {
                return testField;
            }
            set {
                testField;= value;
            }
        }
    }
4

1 に答える 1

5

TestStringXmlText代わりに で飾りXmlElementます。

于 2012-07-25T21:39:11.017 に答える