反序列化包含命名空间的XML元素

反序列化包含命名空间的XML元素,xml,xml-namespaces,xml-deserialization,xsd2code,Xml,Xml Namespaces,Xml Deserialization,Xsd2code,我收到了一个XSD模式,从中我使用XSD2代码创建了一个对象 下一步是使用上面生成的对象反序列化示例XML文件 问题是当我尝试反序列化对象时,单个元素的名称空间有问题 我已经为这个问题挣扎了两天了,我想知道在哪里可以找到ie。什么可能是问题 XML已成功反序列化元素 <Order xmlns="" id="97440"> 约翰 在你的C#类中,你需要这样的东西 您也可以为XmlElement设置名称空间 [XmlElement(Namespace ="http://www.

我收到了一个XSD模式,从中我使用XSD2代码创建了一个对象

下一步是使用上面生成的对象反序列化示例XML文件

问题是当我尝试反序列化对象时,单个元素的名称空间有问题

我已经为这个问题挣扎了两天了,我想知道在哪里可以找到ie。什么可能是问题

XML已成功反序列化元素

<Order xmlns="" id="97440">
约翰

在你的C#类中,你需要这样的东西

您也可以为XmlElement设置名称空间

    [XmlElement(Namespace ="http://www.cohowinery.com")]
    public decimal Price;  

致以最诚挚的问候。

也许您需要在XmlElement属性上设置名称空间。
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
    [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://type.domain.com")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://type.domain.com", IsNullable = false)]
[XmlType(AnonymousType = true)]
[XmlRoot(Namespace = "http://type.domain.com")]
public class Order
{
    [XmlAttribute("id")]
    public string Id { get; set; }
    [XmlElement(Namespace ="http://www.cohowinery.com")]
    public decimal Price;  
}
    [XmlElement(Namespace ="http://www.cohowinery.com")]
    public decimal Price;