0

有人可以指导我如何在正确的位置获得命名空间。目前我得到以下信息:

<agr:ABWInvoice 
    xmlns:agr="http://services.agresso.com/schema/ABWInvoice/2011/11/14"
    xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd" 
    xmlns:agrlib="http://services.agresso.com/schema/ABWSchemaLib/2011/11/14" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 >

我想要这样的东西:

<agr:ABWInvoice 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:agrlib="http://services.agresso.com/schema/ABWSchemaLib/2011/11/14" 
    xmlns:agr="http://services.agresso.com/schema/ABWInvoice/2011/11/14" 
    xsi:schemaLocation="http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd"
>

我添加这样的命名空间:

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("agrlib", "http://services.agresso.com/schema/ABWSchemaLib/2011/11/14");
ns.Add("agr", "http://services.agresso.com/schema/ABWInvoice/2011/11/14");

发票长这样:

    [Serializable]
    [XmlRootAttribute("ABWInvoice", Namespace = "http://services.agresso.com/schema/ABWInvoice/2011/11/14")]
    public class ABWInvoice
    {
        private List<Invoice> _invoice = new List<Invoice>();

        [XmlAttributeAttribute("schemaLocation", AttributeName = "schemaLocation", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
        public string SchemaLocation = "http://services.agresso.com/schema/ABWInvoice/2011/11/14 http://services.agresso.com/schema/ABWInvoice/2011/11/14/ABWInvoice.xsd";

        [XmlElement("Invoice", Namespace = "http://services.agresso.com/schema/ABWInvoice/2011/11/14")]
        public List<Invoice> Invoices
        {
            get { return (_invoice); }
            set { _invoice = value; }
        }
    }
4

0 回答 0