XmlElement反序列化的C#InnerXml

时间:2016-08-17 14:42:17

标签: c# xml

我的内部XML看起来像:

<approving xmlns="uz:rwc:fdu-92:1.0">
    <fdu92>
        <general num="25120001" date="25.12.2013" payment_kind="tehpd" sum="22200" />
        <station code="370006" name="Test" road_short_name="Test" />
        <cargo-owner code="7765" name="Test Subject" />
        <payer code="7395392" name="Test Subject" />
        <references>
            <reference num="11111" doc_name="soma document">
                <payments>
                    <payment code="158" subcode="001" name="Some work" reason="unknown" sum="22200" expended_count="1" />
                </payments>
            </reference>
        </references>
    </fdu92>
</approving>
<signature xmlns="uz:rwc:fdu-92:1.0">Many thousands of symbols</signature>

当我尝试通过在线工具xml to classes从Xml构建类时 它返回Invalid Xml

因为它有

<signature xmlns="uz:rwc:fdu-92:1.0">Many thousands of symbols</signature>

无标签转换

<signature xmlns="uz:rwc:fdu-92:1.0">Many thousands of symbols</signature> 

给出了好的结果

namespace Xml2CSharp
{
    [XmlRoot(ElementName="general", Namespace="uz:rwc:fdu-92:1.0")]
    public class General {
        [XmlAttribute(AttributeName="num")]
        public string Num { get; set; }
        [XmlAttribute(AttributeName="date")]
        public string Date { get; set; }
        [XmlAttribute(AttributeName="payment_kind")]
        public string Payment_kind { get; set; }
        [XmlAttribute(AttributeName="sum")]
        public string Sum { get; set; }
    }

    [XmlRoot(ElementName="station", Namespace="uz:rwc:fdu-92:1.0")]
    public class Station {
        [XmlAttribute(AttributeName="code")]
        public string Code { get; set; }
        [XmlAttribute(AttributeName="name")]
        public string Name { get; set; }
        [XmlAttribute(AttributeName="road_short_name")]
        public string Road_short_name { get; set; }
    }

    [XmlRoot(ElementName="cargo-owner", Namespace="uz:rwc:fdu-92:1.0")]
    public class Cargoowner {
        [XmlAttribute(AttributeName="code")]
        public string Code { get; set; }
        [XmlAttribute(AttributeName="name")]
        public string Name { get; set; }
    }

    [XmlRoot(ElementName="payer", Namespace="uz:rwc:fdu-92:1.0")]
    public class Payer {
        [XmlAttribute(AttributeName="code")]
        public string Code { get; set; }
        [XmlAttribute(AttributeName="name")]
        public string Name { get; set; }
    }

    [XmlRoot(ElementName="payment", Namespace="uz:rwc:fdu-92:1.0")]
    public class Payment {
        [XmlAttribute(AttributeName="code")]
        public string Code { get; set; }
        [XmlAttribute(AttributeName="subcode")]
        public string Subcode { get; set; }
        [XmlAttribute(AttributeName="name")]
        public string Name { get; set; }
        [XmlAttribute(AttributeName="reason")]
        public string Reason { get; set; }
        [XmlAttribute(AttributeName="sum")]
        public string Sum { get; set; }
        [XmlAttribute(AttributeName="expended_count")]
        public string Expended_count { get; set; }
    }

    [XmlRoot(ElementName="payments", Namespace="uz:rwc:fdu-92:1.0")]
    public class Payments {
        [XmlElement(ElementName="payment", Namespace="uz:rwc:fdu-92:1.0")]
        public Payment Payment { get; set; }
    }

    [XmlRoot(ElementName="reference", Namespace="uz:rwc:fdu-92:1.0")]
    public class Reference {
        [XmlElement(ElementName="payments", Namespace="uz:rwc:fdu-92:1.0")]
        public Payments Payments { get; set; }
        [XmlAttribute(AttributeName="num")]
        public string Num { get; set; }
        [XmlAttribute(AttributeName="doc_name")]
        public string Doc_name { get; set; }
    }

    [XmlRoot(ElementName="references", Namespace="uz:rwc:fdu-92:1.0")]
    public class References {
        [XmlElement(ElementName="reference", Namespace="uz:rwc:fdu-92:1.0")]
        public Reference Reference { get; set; }
    }

    [XmlRoot(ElementName="fdu92", Namespace="uz:rwc:fdu-92:1.0")]
    public class Fdu92 {
        [XmlElement(ElementName="general", Namespace="uz:rwc:fdu-92:1.0")]
        public General General { get; set; }
        [XmlElement(ElementName="station", Namespace="uz:rwc:fdu-92:1.0")]
        public Station Station { get; set; }
        [XmlElement(ElementName="cargo-owner", Namespace="uz:rwc:fdu-92:1.0")]
        public Cargoowner Cargoowner { get; set; }
        [XmlElement(ElementName="payer", Namespace="uz:rwc:fdu-92:1.0")]
        public Payer Payer { get; set; }
        [XmlElement(ElementName="references", Namespace="uz:rwc:fdu-92:1.0")]
        public References References { get; set; }
    }

    [XmlRoot(ElementName="approving", Namespace="uz:rwc:fdu-92:1.0")]
    public class Approving {
        [XmlElement(ElementName="fdu92", Namespace="uz:rwc:fdu-92:1.0")]
        public Fdu92 Fdu92 { get; set; }
        [XmlAttribute(AttributeName="xmlns")]
        public string Xmlns { get; set; }
    }

}

当我尝试反序列化对象时

DeserializeFromXmlElement<Approving>(FDU92Xml); 

public static T DeserializeFromXmlElement<T>(XmlElement element)
{
    var serializer = new XmlSerializer(typeof(T));
    return (T)serializer.Deserialize(new XmlNodeReader(element));
}

我收到错误

  

xml文档包含错误

如何修复错误?如何在反序列化过程中忽略signature

0 个答案:

没有答案