|
@@ -7,6 +7,9 @@ class ParserFile extends CI_Controller
|
7
|
7
|
protected $rutaMensual = FCPATH . "DOWNLOADS/MONTH/format";
|
8
|
8
|
protected $esquema = array('cbc-place-ext', 'cac-place-ext', 'cbc', 'cac', 'ns1');
|
9
|
9
|
|
|
10
|
+ //TODO: Añadir los nodos que falten mirando la libreria de java
|
|
11
|
+ //TODO: Crear las tablas segun el nodo
|
|
12
|
+ //TODO: Insertar los datos que si existen en el insert_batch.
|
10
|
13
|
public function __construct()
|
11
|
14
|
{
|
12
|
15
|
parent::__construct();
|
|
@@ -435,80 +438,80 @@ class ParserFile extends CI_Controller
|
435
|
438
|
return $haystack;
|
436
|
439
|
}
|
437
|
440
|
|
438
|
|
- /* public function xml2array($xml)
|
439
|
|
- {
|
440
|
|
- $arr = array();
|
|
441
|
+ /* public function xml2array($xml)
|
|
442
|
+{
|
|
443
|
+$arr = array();
|
441
|
444
|
|
442
|
|
- foreach ($xml->getNamespaces() + array(null) as $prefix => $namespace) {
|
443
|
|
- foreach ($xml->attributes($namespace) as $key => $value) {
|
444
|
|
- // Add prefixes to prefixed attributes
|
445
|
|
- if (is_string($prefix)) {
|
446
|
|
- $key = $prefix . '.' . $key;
|
447
|
|
- }
|
448
|
|
- $arr['@attributes'][$key] = (string) $value;
|
449
|
|
- }
|
450
|
|
- }
|
|
445
|
+foreach ($xml->getNamespaces() + array(null) as $prefix => $namespace) {
|
|
446
|
+foreach ($xml->attributes($namespace) as $key => $value) {
|
|
447
|
+// Add prefixes to prefixed attributes
|
|
448
|
+if (is_string($prefix)) {
|
|
449
|
+$key = $prefix . '.' . $key;
|
|
450
|
+}
|
|
451
|
+$arr['@attributes'][$key] = (string) $value;
|
|
452
|
+}
|
|
453
|
+}
|
451
|
454
|
|
452
|
|
- foreach ($xml as $name => $element) {
|
453
|
|
- $value = $element->children() ? $this->xml2array($element) : trim($element);
|
454
|
|
- if ($value) {
|
455
|
|
- if (!isset($arr[$name])) {
|
456
|
|
- $arr[$name] = $value;
|
457
|
|
- } else {
|
458
|
|
- foreach ((array) $value as $k => $v) {
|
459
|
|
- if (is_numeric($k)) {
|
460
|
|
- $arr[$name][] = $v;
|
461
|
|
- } else {
|
462
|
|
- $arr[$name][$k] = array_merge(
|
463
|
|
- (array) $arr[$name][$k],
|
464
|
|
- (array) $v
|
465
|
|
- );
|
466
|
|
- }
|
467
|
|
- }
|
468
|
|
- }
|
469
|
|
- }
|
470
|
|
- }
|
|
455
|
+foreach ($xml as $name => $element) {
|
|
456
|
+$value = $element->children() ? $this->xml2array($element) : trim($element);
|
|
457
|
+if ($value) {
|
|
458
|
+if (!isset($arr[$name])) {
|
|
459
|
+$arr[$name] = $value;
|
|
460
|
+} else {
|
|
461
|
+foreach ((array) $value as $k => $v) {
|
|
462
|
+if (is_numeric($k)) {
|
|
463
|
+$arr[$name][] = $v;
|
|
464
|
+} else {
|
|
465
|
+$arr[$name][$k] = array_merge(
|
|
466
|
+(array) $arr[$name][$k],
|
|
467
|
+(array) $v
|
|
468
|
+);
|
|
469
|
+}
|
|
470
|
+}
|
|
471
|
+}
|
|
472
|
+}
|
|
473
|
+}
|
471
|
474
|
|
472
|
|
- if ($content = trim((string) $xml)) {
|
473
|
|
- $arr[] = $content;
|
474
|
|
- }
|
|
475
|
+if ($content = trim((string) $xml)) {
|
|
476
|
+$arr[] = $content;
|
|
477
|
+}
|
475
|
478
|
|
476
|
|
- return $arr;
|
477
|
|
- }
|
478
|
|
- $reader = new \XMLReader;
|
479
|
|
- $reader->open($file); // where $path is the file path to the xml file
|
480
|
|
-
|
481
|
|
- // using a dirty trick to skip most of the xml that is irrelevant where $nodeName is the node im looking for
|
482
|
|
- // then in the next while loop i skip to the next node
|
483
|
|
- $data = array();
|
484
|
|
- while ($reader->read() && $reader->name !== "data");
|
485
|
|
- while ($reader->name === "data") {
|
486
|
|
- $doc = new \DOMDocument;
|
487
|
|
- $dom = $doc->importNode($reader->expand(), true);
|
488
|
|
- $data = $this->processDom($dom);
|
489
|
|
- $reader->next($dom->localName);
|
490
|
|
- }
|
|
479
|
+return $arr;
|
|
480
|
+}
|
|
481
|
+$reader = new \XMLReader;
|
|
482
|
+$reader->open($file); // where $path is the file path to the xml file
|
|
483
|
+
|
|
484
|
+// using a dirty trick to skip most of the xml that is irrelevant where $nodeName is the node im looking for
|
|
485
|
+// then in the next while loop i skip to the next node
|
|
486
|
+$data = array();
|
|
487
|
+while ($reader->read() && $reader->name !== "data");
|
|
488
|
+while ($reader->name === "data") {
|
|
489
|
+$doc = new \DOMDocument;
|
|
490
|
+$dom = $doc->importNode($reader->expand(), true);
|
|
491
|
+$data = $this->processDom($dom);
|
|
492
|
+$reader->next($dom->localName);
|
|
493
|
+}
|
491
|
494
|
|
492
|
|
- public function processDom(\DOMNode $node)
|
493
|
|
- {
|
494
|
|
- $data = [];
|
495
|
|
- /** @var \DomNode $childNode
|
496
|
|
- foreach ($node->childNodes as $childNode) {
|
497
|
|
- // child nodes include of a lot of #text nodes which are irrelevant for me, so i just skip them
|
498
|
|
- if ($childNode->nodeName === '#text') {
|
499
|
|
- continue;
|
500
|
|
- }
|
501
|
|
- $childData = $this->processDom($childNode);
|
502
|
|
- if ($childData === null || $childData === []) {
|
503
|
|
- $data[$childNode->localName] = $childNode->nodeValue;
|
504
|
|
- } else {
|
505
|
|
- $data[$childNode->localName] = $childData;
|
506
|
|
- }
|
507
|
|
- }
|
508
|
|
- return $data;
|
509
|
|
- }
|
510
|
|
-
|
511
|
|
- */
|
|
495
|
+public function processDom(\DOMNode $node)
|
|
496
|
+{
|
|
497
|
+$data = [];
|
|
498
|
+/** @var \DomNode $childNode
|
|
499
|
+foreach ($node->childNodes as $childNode) {
|
|
500
|
+// child nodes include of a lot of #text nodes which are irrelevant for me, so i just skip them
|
|
501
|
+if ($childNode->nodeName === '#text') {
|
|
502
|
+continue;
|
|
503
|
+}
|
|
504
|
+$childData = $this->processDom($childNode);
|
|
505
|
+if ($childData === null || $childData === []) {
|
|
506
|
+$data[$childNode->localName] = $childNode->nodeValue;
|
|
507
|
+} else {
|
|
508
|
+$data[$childNode->localName] = $childData;
|
|
509
|
+}
|
|
510
|
+}
|
|
511
|
+return $data;
|
|
512
|
+}
|
|
513
|
+
|
|
514
|
+ */
|
512
|
515
|
|
513
|
516
|
}
|
514
|
517
|
|