Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/09/2014, 14:19
Avatar de YeisonSoto
YeisonSoto
 
Fecha de Ingreso: enero-2011
Ubicación: Cali, Colombia, Colombia
Mensajes: 116
Antigüedad: 13 años, 3 meses
Puntos: 4
Recorrer XML insertar atributos en BD

Buenas Tardes Amigos del foro, Debo leer un XML completo y guardar los atributos de cada nodo en una base de datos PostgreSQl.

El XML ya lo estoy recorriendo en su totalidad y estoy mostrando sus valores

trozo del XMl (Es mucho mas extenso)

Código XML:
Ver original
  1. <CuentaAhorro  fechaApertura="2012-12-13" calificacion="123" situacionTitular="123" oficina="123" ciudad="123" codigoDaneCiudad="123" codSuscriptor="123" tipoIdentificacion="123" identificacion="123" sector="123">
  2.             <Caracteristicas clase="123" />
  3.             <Estado codigo="123" fecha="2012-12-13" />
  4.             <Reclamo numero="123" tipoLeyenda="123" tipo="123" fecha="2012-12-13" estado="123" ratificado="true" numeroCuenta="123" texto="123" entidad="123" fechaCierre="2012-12-13">
  5.                 <Subtipo codigo="123" nombre="123" />
  6.                 <Llave>123</Llave>
  7.             </Reclamo>
  8.             <Adjetivo codigo="123" fecha="2012-12-13" />
  9.             <Llave>123</Llave>
  10.  </CuentaAhorro>



Código PHP:
Ver original
  1. function fnRecorreXmlRecursivo($xmlObj, $depth = 0) {
  2.         if ($depth == 0) {
  3.             $this->padre = $xmlObj->children()->getName();
  4.           }
  5.         $anterior = $xmlObj;
  6.         foreach ($xmlObj->children() as $hijo) {//caracteristica
  7.             echo "<br>";
  8.             if (count($hijo->children()) <= 0) {//No  tiene hijos
  9.                 echo str_repeat('-', $depth) . "<strong>" . $this->padre . $anterior->getName() . $hijo->getName() . "</strong>_<strong></strong>";// . $hijo->getName();
  10.             } else {
  11.                 echo str_repeat('-', $depth) . "<strong>" . $anterior->getName() . $hijo->getName() . "</strong>_";
  12.             }
  13.             foreach ($hijo->attributes() as $attr) {
  14.                 echo $attr->getName() . "|" . $attr . ";";
  15.             }
  16.             $this->fnRecorreXmlRecursivo($hijo, $depth + 1);
  17.         }
  18.     }

el resultado que obtengo es este:

-InformeCuentaAhorro_bloqueada|true;entidad|123;numero|123;fechaApertu ra|2012-12-13;calificacion|123;situacionTitular|123;oficina|1 23;ciudad|123;codigoDaneCiudad|123;codSuscriptor|1 23;tipoIdentificacion|123;identificacion|123;secto r|123;
--InformeCuentaAhorroCaracteristicas_clase|123;
--CuentaAhorroValores_
---InformeValoresValor_moneda|123;creditosEfectivo|3.1415926535;debitosE fectivo|3.1415926535;creditosTransferencia|3.14159 26535;debitosTransferencia|3.1415926535;fecha|2012-12-13;calificacion|123;
--InformeCuentaAhorroEstado_codigo|123;fecha|2012-12-13;
--CuentaAhorroReclamo_numero|123;tipoLeyenda|123;tipo|123;fecha|2012-12-13;estado|123;ratificado|true;numeroCuenta|123;tex to|123;entidad|123;fechaCierre|2012-12-13;
---InformeReclamoSubtipo_codigo|123;nombre|123;
---InformeReclamoLlave_
--InformeCuentaAhorroAdjetivo_codigo|123;fecha|2012-12-13;
--InformeCuentaAhorroLlave_

Las llaves deberia ser asi:

-InformeCuentaAhorro
--InformeCuentaAhorroCaracteristicas
--InformeCuentaAhorroValores
---InformeCuentaAhorroValoresValor
--InformeCuentaAhorroEstado
--InformeCuentaAhorroReclamo
---InformeCuentaAhorroReclamoSubtipo
---InformeCuentaAhorroReclamoLlave
--InformeCuentaAhorroAdjetivo
--InformeCuentaAhorroLlave


Agradezco la ayuda que me puedan dar