2010-08-11 47 views
2

我想用C#序列化xml中的下列結構。我想序列化命名空間

<?xml version="1.0" encoding="UTF-8"?> 
... 
<complement> 
<hello:world color="0" number="1" > 
</complement> 
... 

...或類似的東西。我感興趣的命名空間和屬性的序列化:P

[(namespace)] 
class { } 

感謝

回答

2

您可以指定不同的XML序列化屬性的命名空間。這裏是一個樣本:

[XmlRoot(Namespace = "http://schemas.fabrikam.com/mynamespace")] 
[XmlType(Namespace = "http://schemas.fabrikam.com/mynamespace")] 
public class MyObject 
{ 
    [XmlElement(Namespace = "http://schemas.fabrikam.com/anothernamespace")] 
    public string MyElement { get; set; } 

    [XmlAttribute(Namespace = "http://schemas.fabrikam.com/yetanothernamespace")] 
    public string MyAttribute { get; set; } 
} 
相關問題