如何格式化xml对象类的值

时间:2019-05-25 10:31:11

标签: c# xml

我有一个XML。我已经将其转换为类文件,因此可以将值传递到该节点的xml对象中。但是我坚持要传递下面这个对象的值。您能描述一下我该如何编写相同的代码。最后一个问题是我提供了我的代码

<m:SaveOrder xmlns:m = 'http://www.e-courier.com/schemas/' >

下面是xml

<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/' > 
  <SOAP:Body UserGUID = '{redacted}' > 
    <m:SaveOrder xmlns:m = 'http://www.e-courier.com/schemas/' > 
         <Order UserID = '1' Notes = 'Pick CVS Lenexa.' CustomerID = '3' > 
 </Order >  
 </m:SaveOrder > 
 </SOAP:Body >
 </SOAP:Envelope>

下面是为xml创建的类。

[XmlRoot(ElementName="Order")]
    public class Order {
        [XmlAttribute(AttributeName="UserID")]
        public string UserID { get; set; }
        [XmlAttribute(AttributeName="Notes")]
        public string Notes { get; set; }
        [XmlAttribute(AttributeName="CustomerID")]
        public string CustomerID { get; set; }
    }

    [XmlRoot(ElementName="SaveOrder", Namespace="http://www.e-courier.com/schemas/")]
    public class SaveOrder {
        [XmlElement(ElementName="Order")]
        public Order Order { get; set; }
        [XmlAttribute(AttributeName="m", Namespace="http://www.w3.org/2000/xmlns/")]
        public string M { get; set; }
    }

    [XmlRoot(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
    public class Body {
        [XmlElement(ElementName="SaveOrder", Namespace="http://www.e-courier.com/schemas/")]
        public SaveOrder SaveOrder { get; set; }
        [XmlAttribute(AttributeName="UserGUID")]
        public string UserGUID { get; set; }
    }

    [XmlRoot(ElementName="Envelope", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
    public class Envelope {
        [XmlElement(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
        public Body Body { get; set; }
        [XmlAttribute(AttributeName="SOAP", Namespace="http://www.w3.org/2000/xmlns/")]
        public string SOAP { get; set; }
    }

我卡住的代码

var SaveOrder = new ECSaveOrderRequest.Envelope
           {
             Body = new ECSaveOrderRequest.Body
               {
                 UserGUID = guid,
                 SaveOrder = new ECSaveOrderRequest.SaveOrder
                 {

                 }

               }
            };

0 个答案:

没有答案