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