2012-07-25 89 views
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; 
      } 
     } 
    } 
+0

我不知道完整的答案,但我認爲它將實現'標準化'上的'ToString'來返回'testField',然後使用一些屬性來說'Standardize'只是一個字符串。 – 2012-07-25 21:19:23

回答

5

裝飾TestStringXmlText而不是XmlElement

+0

完美,謝謝。 – 2012-07-25 21:56:41