2009-04-28 85 views

回答

69

[XmlText],就像這樣:

using System; 
using System.Xml.Serialization; 
[Serializable, XmlRoot("myElement")] 
public class MyType { 
    [XmlAttribute("name")] 
    public string Name {get;set;} 

    [XmlText] 
    public string Text {get;set;} 
} 
static class Program { 
    static void Main() { 
     new XmlSerializer(typeof(MyType)).Serialize(Console.Out, 
      new MyType { Name = "foo", Text = "bar" }); 
    } 
} 
+0

感謝了很多,只是沒有找到這個XMLTEXT :) – 2009-04-28 09:50:28