Ver Mensaje Individual
  #1  
Antiguo 01-03-2022
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Ubicación: Toledo - España
Posts: 1.418
Reputación: 21
Angel.Matilla Va por buen camino
Leer un fichero XML

Buenas. Estoy implementando en una aplicación el poder cargar un fichero XML de recibos (Órdenes en formato ISO 20022 para emisión de Adeudos Directos SEPA) que se ha creado en otra máquina para mantener la BB.DD. actualizada.
El fichero tiene esta estructura:
Código:
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <CstmrDrctDbtInitn>
    <GrpHdr>
      <MsgId>8DA16A62A6954A25BBD465B830D0BD49</MsgId>
      <CreDtTm>2020-0730T09:56:43</CreDtTm>
      <NbOfTxs>15</NbOfTxs>
      <CtrlSum>580.00</CtrlSum>
      <InitgPty>
        <Nm>XXXXXXXXX</Nm>
        <Id>
          <OrgId>
            <Othr>
              <Id>XXXXXXXXXXXXX</Id>
            </Othr>
          </OrgId>
        </Id>
      </InitgPty>
    </GrpHdr>
    <PmtInf>
      <PmtInfId>15323007200955</PmtInfId>
      <PmtMtd>DD</PmtMtd>
      <NbOfTxs>15</NbOfTxs>
      <CtrlSum>580.00</CtrlSum>
      <PmtTpInf>
        <SvcLvl>
          <Cd>SEPA</Cd>
        </SvcLvl>
        <LclInstrm>
          <Cd>CORE</Cd>
        </LclInstrm>
        <SeqTp>RCUR</SeqTp>
      </PmtTpInf>
      <ReqdColltnDt>2020-08-02</ReqdColltnDt>
      <Cdtr>
        <Nm>XXXXXXXXXX</Nm>
      </Cdtr>
      <CdtrAcct>
        <Id>
          <IBAN>ES533190XXXXXXXXXXXXX</IBAN>
        </Id>
      </CdtrAcct>
      <CdtrAgt>
        <FinInstnId>
          <BIC>BCOEESMM190</BIC>
        </FinInstnId>
      </CdtrAgt>
      <CdtrSchmeId>
        <Id>
          <PrvtId>
            <Othr>
              <Id>XXXXXXXXXXXXXXX</Id>
              <SchmeNm>
                <Prtry>SEPA</Prtry>
              </SchmeNm>
            </Othr>
          </PrvtId>
        </Id>
      </CdtrSchmeId>
      <DrctDbtTxInf>
        <PmtId>
          <EndToEndId>1150412</EndToEndId>
        </PmtId>
        [...]
      </DrctDbtTxInf>
      [...]
    </PmtInf>
    <PmtInf>
      [...]
    </PmtInf>
  </CstmrDrctDbtInitn>
</Document>
El primer trozo, entre las etiquetas <GrpHdr> y </GrpHdr>, es único para cada fichero. Luego puede haber un número indeterminado de grupos <PmtInf> - </PmtInf>. Para leer el fichero estoy haciendo esto:
Código:
XMLDocument->Active = true;
iNode0 = XMLDocument->DocumentElement;
iNode1 = iNode0->ChildNodes->FindNode("CstmrDrctDbtInitn");
if (iNode1 == NULL)
     continue;

iNode2 = iNode1->ChildNodes->FindNode("GrpHdr");
if (iNode2 == NULL)
     continue;

iNode2 = iNode1->ChildNodes->FindNode("PmtInf");
while (iNode2 != NULL)
{
     iNode3 = iNode2->ChildNodes->FindNode("PmtInfId");
     if (iNode3 != NULL && iNode3->IsTextElement)
     {
          cRefInt = (DOMString)iNode3->Text;
          etc.
     }
     iNode2 = iNode2->NextSibling();
}
La primera vez que entra encuentar correctamente la primera etiqueta PmtInf y ejecuta todo el código que sigue pero al llegar al NextSibling, aunque haya otra etiqueta PmtInf no la encuentra y se sale del bucle. Con la ayuda de Builder había entendido que NextSibling seguía ejecutándo el bucle mientars encontrara la etiqueta correspondiente y tal vez haya interpretado mal su funcionamiento.
Responder Con Cita