0

need a node with prefix, but he does it the right way, is a failure of the way I do? or is a compiler bug?

main module code

    function Generar_Addenda(PathCFD : String; ValidaOnly : Integer) : Integer;
const
  xmlns = 'xmlns=""';             (* Cadena String a Borrar, (se genera al obtener la interaz Factura) *)
var
  XMLFactura : IXMLDocument;
  Factura : IXMLFactura;
  CFD : TCFD;
begin

  Try
    CFD := TCFD.Create(cfdV22);       // AQUI CREO UNA INSTANCIA DEL CFD, PARA TENER LA CLASE COMPLETA
    CFD.LoadFromFile(PathCFD);       // AQUI CARGO EL XML YA SELLADO, LISTO PARA PEGAR LA ADDENDA

    XMLFactura := TXMLDocument.Create(Nil);
    XMLFactura.Active := True;

    Factura := GetFactura(XMLFactura);

// ************* PERSONALIZAR ADDENDA CHRYSLER PPY  **********************             AQUI LLENO LA ADDENDA CON LOS DATOS DE LA BASE DE DATOS
    With Factura do
     begin
       TipoDocumento := cds_cliente.FieldByName('TipoDocumento').AsString;
       TipoDocumentoFiscal := cds_Cliente.FieldByName('TipoDocumentoFiscal').AsString;   
       Version := cds_Cliente.FieldByName('Version').AsString;
      ......
      .....
    end;

    FACTURA.OwnerDocument.Options := [doAutoPrefix];


    CFD.Datos.Addenda.ChildNodes.Add(Factura);

    Factura.SetAttributeNS('xmlns:PPY','', 'http://www.dfdchryslerdemexico.com.mx/Addenda/PPY');
    Factura.Attributes['xsi:schemaLocation'] :=  'http://www.dfdchryslerdemexico.com.mx/Addenda/PPY http://www.dfdchryslerdemexico.com.mx/Addenda/PPY/PPY.XSD';

    CFD.SaveToFile('C:\Paso\CFD_PRUEBA_ADDENDA_CHRYSLER.XML');
  Finally
     ......
     ......

  End;

I made ​​changes in the interface Intf_PPY I made were the following, in PPY prepend node name will factura

    function Getfactura(Doc: IXMLDocument): IXMLFactura;
function Loadfactura(const FileName: string): IXMLFactura;
function Newfactura: IXMLFactura;

const
  TargetNamespace =
   'http://www.dfdchryslerdemexico.com.mx/Addenda/PPY'; // xsi:schemaLocation="http://www.dfdchryslerdemexico.com.mx/Addenda/PPY http://www.dfdchryslerdemexico.com.mx/Addenda/PPY/PPY.XSD"';

implementation

{ Global Functions }

function Getfactura(Doc: IXMLDocument): IXMLFactura;
begin
  Result := Doc.GetDocBinding('PPY:factura', TXMLFactura, TargetNamespace) as IXMLFactura;
end;

function Loadfactura(const FileName: string): IXMLFactura;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('PPY:factura', TXMLFactura, TargetNamespace) as IXMLFactura;
end;

function Newfactura: IXMLFactura;
begin
  Result := NewXMLDocument.GetDocBinding('PPY:factura', TXMLFactura, TargetNamespace) as IXMLFactura;
end;

and this is what I find, with the nodes note, otroscargos, part no prefix, but with the namespace included within them

    <Addenda>
      <PPY:factura tipoDocumento="PPY" TipoDocumentoFiscal="FA" version="1.0" serie="A" folioFiscal="451" fecha="2012-06-20" montoTotal="9960.98" referenciaProveedor="A 451" xmlns:PPY="http://www.dfdchryslerdemexico.com.mx/Addenda/PPY" xsi:schemaLocation="http://www.dfdchryslerdemexico.com.mx/Addenda/PPY http://www.dfdchryslerdemexico.com.mx/Addenda/PPY/PPY.XSD">
         <PPY:moneda tipoMoneda="USD" tipoCambio="1.0000"/>
         <PPY:proveedor codigo="20215" nombre="NOMBRE DE LA EMPRESA S.A. DE C.V."/>
         <PPY:destino codigo="8476" nombre="PLANTA DE MOTORES 4 CILINDROS - SALTILLO"/>
         <nota xmlns="http://www.dfdchryslerdemexico.com.mx/Addenda/PPY">Addenda de Prueba</nota>
         <otrosCargos xmlns="http://www.dfdchryslerdemexico.com.mx/Addenda/PPY" codigo="V6" monto="1373.93"/>
         <PPY:partes>
            <part xmlns="http://www.dfdchryslerdemexico.com.mx/Addenda/PPY" numero="123456" cantidad="1.0000" unidadDeMedida="EA" precioUnitario="8587.0500" montoDeLinea="8587.05">
               <references ordenCompra="XYZ6675" releaseRequisicion="XYZ4218000" ammendment="A"/>
               <nota>Probando Addenda</nota>
            </part>
         </PPY:partes>
      </PPY:factura>
   </Addenda>

I'm doing something wrong? or is there another way that works?

thanks

TLama
  • 75,147
  • 17
  • 214
  • 392

1 Answers1

1

You have to make sure the namespace ad prefix are registered with the DOM before you can use them effectively on child nodes and attributes. Your nota, ostrosCargos, and part nodes end up with their own xmlns attributes if you are specifying a namespace when creating them, but you did not previously register that namespace with the factura node. It is not enough to just create an xmlns attribute manually like you are currently doing. You need to actually register the namespace with the DOM so it knows about it and can use it when needed.

Have a look at this discussion on the Embarcadero forum for tips on how to work with namespaced nodes in the implementation code that the XML Data Binding wizard creates:

Creating a doc with two namespaces

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • **all nodes are registered with the function RegisterChildNodes Afterconstruction of TXMLFactura, others are collections** `FCargosCreditos := CreateCollection(TXMLFactura_cargosCreditosList, IXMLFactura_cargosCreditos, 'cargosCreditos') as IXMLFactura_cargosCreditosList; FOtrosCargos := CreateCollection(TXMLFactura_otrosCargosList, IXMLFactura_otrosCargos, 'otrosCargos') as IXMLFactura_otrosCargosList;` – Francisco Banda Dec 15 '12 at 00:16
  • 'RegisterChildNode('otrosCargos', TXMLFactura_otrosCargos); RegisterChildNode('partes', TXMLFactura_partes);' – Francisco Banda Dec 15 '12 at 00:55