No soy experto en delphi, pero empiricamente he estado trabajando en un proyecto.
El XML lo he estado resolviendo de este modo, a ver si te es útil. OJO que la extructura del xml aún falta corregir.
Código Delphi
[-]Var
FirmarXML: TCFXML;
Zip: TZipFile;
tDocXmlNombre: string;
Xml: IXMLDOCUMENT;
nMaster, nPrimero, nSegundo, nTercero, nCuarto, nQuinto, nAtributo, nItem,
nItemSub, nCDATA: IXMLNODE;
begin
Xml := NewXMLDocument;
Xml.Version := '1.0';
Xml.Encoding := 'UTF-8';
Xml.Options := [doNodeAutoIndent];
nMaster := Xml.AddChild('Invoice');
nMaster.Attributes['xmlns'] :=
'urnasis:names:specification:ubl:schema:xsd:Invoice-2';
nMaster.Attributes['xmlns:cac'] :=
'urnasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2';
nMaster.Attributes['xmlns:cbc'] :=
'urnasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2';
nMaster.Attributes['xmlns:ccts'] := 'urn:un:unece:uncefact:documentation:2';
nMaster.Attributes['xmlns:ds'] := 'http://www.w3.org/2000/09/xmldsig#';
nMaster.Attributes['xmlns:ext'] :=
'urnasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2';
nMaster.Attributes['xmlns:qdt'] :=
'urnasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2';
nMaster.Attributes['xmlns:udt'] :=
'urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2';
nMaster.Attributes['xmlns:xsi'] :=
'http://www.w3.org/2001/XMLSchema-instance';
nPrimero := nMaster.AddChild('ext:UBLExtensions');
nSegundo := nPrimero.AddChild('ext:UBLExtension');
nSegundo.AddChild('ext:ExtensionContent').Text := '';
nPrimero := nMaster.AddChild('cbc:UBLVersionID');
nPrimero.Text := '2.1';
nPrimero := nMaster.AddChild('cbc:CustomizationID');
nPrimero.Text := '2.0';
nPrimero := nMaster.AddChild('cbc:ID');
nPrimero.Text := edtSerie.Text + '-' +
FEnumCBT(FloatToStr(edtNumeracion.Value), 7, '0', False);
nPrimero := nMaster.AddChild('cbc:IssueDate');
nPrimero.Text := FormatDateTime('yyyy-mm-dd', edtFechaEmision.Date);
nPrimero := nMaster.AddChild('cbc:InvoiceTypeCode');
nPrimero.Attributes['listID'] := '0101';
nPrimero.Attributes['listAgencyName'] := 'PE:SUNAT';
nPrimero.Attributes['listName'] := 'SUNAT:Identificador de Tipo de Documento';
nPrimero.Attributes['listURI'] :=
'urne:gob:sunat:cpe:see:gem:catalogos:catalogo01';
nPrimero.Text := FEObCodCBT(FEObIntLookup(edtComprobante));
nPrimero := nMaster.AddChild('cbc:Note');
nPrimero.Attributes['languageLocaleID'] := '1000';
nPrimero.Text := 'SON: ' + UpperCase(FELeyendoNUM(txtTotal.Value)) +
' Y 00/100 ' + ObDatoStrInt('monedas', 'id_moneda', 'descripcion',
FEObIntLookup(edtMoneda));
nPrimero := nMaster.AddChild('cbcocumentCurrencyCode');
nPrimero.Attributes['listID'] := 'ISO 4217 Alpha';
nPrimero.Attributes['listName'] := 'Currency';
nPrimero.Attributes['listAgencyName'] :=
'United Nations Economic Commission for Europe';
nPrimero.Text := ObDatoStrInt('monedas', 'id_moneda', 'codigo',
FEObIntLookup(edtMoneda));
nPrimero := nMaster.AddChild('cac:Signature');
nPrimero.AddChild('cbc:ID').Text := tRucEmisor;
nSegundo := nPrimero.AddChild('cac:SignatoryParty');
nTercero := nSegundo.AddChild('cac:PartyIdentification');
nTercero.AddChild('cbc:ID').Text := tRucEmisor;
nCuarto := nSegundo.AddChild('cac:PartyName');
nCuarto.AddChild('cbc:Name').DOMNode.appendChild
(Xml.DOMDocument.createCDATASection(tRazonEmisor));
nSegundo := nPrimero.AddChild('cacigitalSignatureAttachment');
nTercero := nSegundo.AddChild('cac:ExternalReference');
nTercero.AddChild('cbc:URI').Text := tRucEmisor;
nPrimero := nMaster.AddChild('cac:AccountingSupplierParty');
nItem := nPrimero.AddChild('cbc:CustomerAssignedAccountID');
nItem.Text := tRucEmisor; nItem := nPrimero.AddChild('cbc:AdditionalAccountID');
nItem.Text := FE_CodigoTipoDoc(tRucEmisor);
nSegundo := nPrimero.AddChild('cac:Party');
nTercero := nSegundo.AddChild('cac:PartyIdentification');
nAtributo := nTercero.AddChild('cbc:ID');
nAtributo.Attributes['schemeID'] := '6';
nAtributo.Attributes['schemeName'] :=
'SUNAT:Identificador de Documento de Identidad';
nAtributo.Attributes['schemeAgencyName'] := 'PE:SUNAT';
nAtributo.Attributes['schemeURI'] :=
'urne:gob:sunat:cpe:see:gem:catalogos:catalogo06';
nAtributo.Text := tRucEmisor;
nTercero := nSegundo.AddChild('cac:PartyName');
nTercero.AddChild('cbc:Name').DOMNode.appendChild
(Xml.DOMDocument.createCDATASection(tRazonEmisor));
nTercero := nSegundo.AddChild('cac:PartyLegalEntity');
nTercero.AddChild('cbc:RegistrationName').DOMNode.appendChild
(Xml.DOMDocument.createCDATASection(tRazonEmisor));
nItem := nTercero.AddChild('cac:RegistrationAddress');
nItem.AddChild('cbc:AddressTypeCode').Text := IntToStr(tUbiGeoEmisor);
nPrimero := nMaster.AddChild('cac:AccountingCustomerParty');
nItem := nPrimero.AddChild('cbc:CustomerAssignedAccountID');
nItem.Text := edtDni.Text; nItem := nPrimero.AddChild('cbc:AdditionalAccountID');
nItem.Text := FE_CodigoTipoDoc(edtDni.Text);
nSegundo := nPrimero.AddChild('cac:Party');
nTercero := nSegundo.AddChild('cac:PartyIdentification');
nAtributo := nTercero.AddChild('cbc:ID');
nAtributo.Attributes['schemeID'] := FE_CodigoTipoDoc(edtDni.Text);
nAtributo.Attributes['schemeName'] :=
'SUNAT:Identificador de Documento de Identidad';
nAtributo.Attributes['schemeAgencyName'] := 'PE:SUNAT';
nAtributo.Attributes['schemeURI'] :=
'urne:gob:sunat:cpe:see:gem:catalogos:catalogo06';
nAtributo.Text := edtDni.Text;
nTercero := nSegundo.AddChild('cac:PartyLegalEntity');
nTercero.AddChild('cbc:RegistrationName').DOMNode.appendChild
(Xml.DOMDocument.createCDATASection(edtNombre.Text));
nPrimero := nMaster.AddChild('cac:TaxTotal');
nSegundo := nPrimero.AddChild('cbc:TaxAmount');
nSegundo.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
'codigo', FEObIntLookup(edtMoneda));
nSegundo.Text := FormatFloat('0.00', txtIgv.Value); nSegundo := nPrimero.AddChild('cac:TaxSubtotal');
nItem := nSegundo.AddChild('cbc:TaxableAmount');
nItem.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
'codigo', FEObIntLookup(edtMoneda));
nItem.Text := FormatFloat('0.00', txtTotal.Value);
nTercero := nSegundo.AddChild('cbc:TaxAmount');
nTercero.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
'codigo', FEObIntLookup(edtMoneda));
nTercero.Text := FormatFloat('0.00', txtSubTotal.Value); nTercero := nSegundo.AddChild('cac:TaxCategory');
nItem := nTercero.AddChild('cbc:ID');
nItem.Attributes['schemeID'] := 'UN/ECE 5305';
nItem.Attributes['schemeName'] := 'Tax Category Identifier';
nItem.Attributes['schemeAgencyName'] :=
'United Nations Economic Commission for Europe';
nItem.Text := 'S';
nCuarto := nTercero.AddChild('cac:TaxScheme');
nQuinto := nCuarto.AddChild('cbc:ID');
nQuinto.Attributes['schemeID'] := 'UN/ECE 5153';
nQuinto.Attributes['schemeAgencyID'] := '6';
nQuinto.Text := IntToStr(IgvObCodigoIntInt(ObIntLookup(edtImpuesto)));
nQuinto := nCuarto.AddChild('cbc:Name');
nQuinto.Text := 'IGV'; nQuinto := nCuarto.AddChild('cbc:TaxTypeCode');
nQuinto.Text := IgvObCntitStrInt(ObIntLookup(edtImpuesto));
nPrimero := nMaster.AddChild('cac:LegalMonetaryTotal');
nSegundo := nPrimero.AddChild('cbc:AllowanceTotalAmount');
nSegundo.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
'codigo', FEObIntLookup(edtMoneda));
nSegundo.Text := FloatToStr(txtDescuento.Value);
nSegundo := nPrimero.AddChild('cbc:PayableAmount');
nSegundo.Attributes['currencyID'] := ObDatoStrInt('monedas', 'id_moneda',
'codigo', FEObIntLookup(edtMoneda));
nSegundo.Text := FloatToStr(txtTotal.Value);