2016-04-22 2 views
0

を持っていけません。この生成された「pruebas.xml」の部分は、この試験であるソースコードXMLは、これは私が実行しているコマンドである輸入属性とpreceders名前空間

var invoice = new InvoiceType(); 

invoice.IssueDate = new IssueDateType(); 
invoice.IssueDate.Value = DateTime.Now; 
var supplier = new SupplierPartyType();    

supplier.CustomerAssignedAccountID = new CustomerAssignedAccountIDType(); 
supplier.CustomerAssignedAccountID.Value = "5461564646";    

supplier.AdditionalAccountID = new AdditionalAccountIDType[1]; 
supplier.AdditionalAccountID[0] = new AdditionalAccountIDType 
{ 
    Value = "6" 
}; 

supplier.Party = new PartyType(); 
supplier.Party.PartyName = new PartyNameType[1]; 
supplier.Party.PartyName[0] = new PartyNameType 
{ 
    Name = new NameType1 { Value = "EMPRESA X" } 
}; 

invoice.AccountingSupplierParty = supplier; 

string fichero = @"E:\InvoiceXsd\pruebas.xml"; 
XmlSerializer serializer = new XmlSerializer(typeof(InvoiceType)); 
FileStream fs = new FileStream(fichero, FileMode.Create); 
serializer.Serialize(fs, invoice); 
fs.Close(); 

の一部である:要素で

<?xml version="1.0"?> 
<Invoice 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"> 

<ID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">F001-10</ID> 
<IssueDate xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2016-04-22</IssueDate> 
<InvoiceTypeCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">01</InvoiceTypeCode> 
<AccountingSupplierParty xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"> 
    <CustomerAssignedAccountID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">20272874680</CustomerAssignedAccountID> 
    <AdditionalAccountID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">6</AdditionalAccountID> 
    <Party> 
     <PartyName> 
      <Name xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">nombre empresa</Name> 
     </PartyName> 
     <PostalAddress> 
      <ID xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">150114</ID> 
      <StreetName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">DIRECCION</StreetName> 
      <CitySubdivisionName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" /> 
      <CityName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">DEPARTAMENTO</CityName> 
      <CountrySubentity xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">DISTRITO</CountrySubentity> 
      <District xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">LUGAR</District> 
      <Country> 
       <IdentificationCode xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">ES</IdentificationCode> 
      </Country> 
     </PostalAddress> 
     <PartyLegalEntity> 
      <RegistrationName xmlns="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">NOMBRE EMPRESA</RegistrationName> 
     </PartyLegalEntity> 
    </Party> 
</AccountingSupplierParty> 

「インボイス」XSDからTHAが生成されたインポートを持っていません.exeコマンド。すべての要素には名前空間xsdがありません。

結果は次のようになります。 :

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><Invoice 
xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" 
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"  
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"  
xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" 
xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" 
xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

<cac:AccountingSupplierParty> 
    <cbc:CustomerAssignedAccountID>20100454523</cbc:CustomerAssignedAccountID> 
    <cbc:AdditionalAccountID>6</cbc:AdditionalAccountID> 
    <cac:Party> 
    <cac:PostalAddress> 
     <cbc:ID>150111</cbc:ID> 
     <cbc:StreetName>AV. LOS PRECURSORES #1245</cbc:StreetName> 
     <cbc:CitySubdivisionName>URB. MIGUEL GRAU</cbc:CitySubdivisionName> 
     <cbc:CityName>LIMA</cbc:CityName> 
     <cbc:CountrySubentity>LIMA</cbc:CountrySubentity> 
     <cbc:District>EL AGUSTINO</cbc:District> 
     <cac:Country> 
     <cbc:IdentificationCode>PE</cbc:IdentificationCode> 
     </cac:Country> 
     </cac:PostalAddress> 
     <cac:PartyLegalEntity> 
     <cbc:RegistrationName>SOPORTE TECNOLOGICOS EIRL</cbc:RegistrationName> 
    </cac:PartyLegalEntity> 
    </cac:Party> 
</cac:AccountingSupplierParty> 

私は間違っていますか?どんな助けでも大歓迎です。

ノードでcbc、cac、... namespace precedersを取得するにはどうすればよいですか?

答えて

1
XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); 
ns.Add("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"); 

...

serializer.Serialize(fs, invoice, ns); 
+0

こんにちは、SOへようこそ。コードフォーマットを追加するには答えを編集してください(不必要なスペースを削除してからコードを選択してctrl-kを押してください)、またその間に説明や解説を追加して、どのように問題を解決するか。ありがとうございました! –

関連する問題