2011-05-15 70 views
2

我已代碼段由XSD工具生成以下代碼:更改名稱XML時Deserialising

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] 
[System.SerializableAttribute()] 
[System.Diagnostics.DebuggerStepThroughAttribute()] 
[System.ComponentModel.DesignerCategoryAttribute("code")] 
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
public partial class myCourseCourseStructureModule 

我想調用類的東西更有意義一點。我需要添加哪些屬性才能讓我輕鬆更改這個屬性?

回答

1

XmlTypeAttribute具有一個構造函數,該構造函數接受一個應該是名稱的字符串: XmlTypeAttribute Constructor on MSDN。如this related post中所述,這將更改模式中複雜類型的名稱。 John Saunders建議使用

[XmlElement(Name="MyAddress", Namespace="your namespace")] 

更改XML中的元素名稱。

0

XmlElementAttribute

// This is the class that will be serialized. 
public class XClass 
{ 
    /* The XML element name will be XName 
    instead of the default ClassName. */ 
    [XmlElement(ElementName = "XName")] 
    public string ClassName; 
} 
+0

@CycleMachine - 你找到答案? – 2011-05-18 17:43:25