| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | class IGSN_Metadata_Base_XMLWriter { |
| 9: | |
| 10: | const SUPPLEMENTALMETADATA = 'supplementalMetadata'; |
| 11: | const RECORD = 'record'; |
| 12: | |
| 13: | protected XMLWriter $regw; |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | function writeElements($regw, $input) { |
| 21: | $this->regw = $regw; |
| 22: | $object_vars = $input->reflekt(); |
| 23: | |
| 24: | |
| 25: | foreach ($object_vars as $name => $value) { |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | if (strcmp($name, self::SUPPLEMENTALMETADATA) == 0) { |
| 31: | $sample = $input->{$name}->getValue(); |
| 32: | $sample = html_entity_decode($sample); |
| 33: | $this->regw->startElement(self::SUPPLEMENTALMETADATA); |
| 34: | $this->regw->startElement(self::RECORD); |
| 35: | $this->regw->writeRaw($sample); |
| 36: | $this->regw->endElement(); |
| 37: | $this->regw->endElement(); |
| 38: | } else { |
| 39: | if (isset($input->{$name}) && $input->{$name}->isdepended == false) { |
| 40: | |
| 41: | $this->regw->startElement($input->{$name}->getKeyname()); |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | if (($input->{$name}->hasattributes)) { |
| 47: | foreach ($input->{$name}->attributes as $attname) { |
| 48: | $this->regw->writeAttribute($attname->getKeyname(), $attname->getValue()); |
| 49: | } |
| 50: | } |
| 51: | |
| 52: | |
| 53: | |
| 54: | if ($input->{$name}->isparenttag == false) { |
| 55: | |
| 56: | $tname = $input->{$name}->getKeyname(); |
| 57: | if (strcmp($tname, 'material') == 0){ |
| 58: | |
| 59: | $this->regw->text(trim($input->{$name}->getValue())); |
| 60: | $this->regw->endElement(); |
| 61: | }else{ |
| 62: | $this->regw->text(trim($input->{$name}->getValue())); |
| 63: | $this->regw->endElement(); |
| 64: | |
| 65: | } |
| 66: | |
| 67: | } else { |
| 68: | foreach ($input->{$name}->children as $child) { |
| 69: | |
| 70: | if (isset($child)) { |
| 71: | |
| 72: | if ($child->isparenttag == false) { |
| 73: | $this->regw->startElement($child->getKeyname()); |
| 74: | if ($child->hasattributes) { |
| 75: | foreach ($child->attributes as $attributeChild) { |
| 76: | $this->regw->writeAttribute($attributeChild->getKeyname(), $attributeChild->getValue()); |
| 77: | } |
| 78: | } |
| 79: | $this->regw->text(trim($child->getValue())); |
| 80: | $this->regw->endElement(); |
| 81: | } else { |
| 82: | $this->regw->startElement($child->getKeyname()); |
| 83: | if ($child->hasattributes) { |
| 84: | foreach ($child->attributes as $attributeChild) { |
| 85: | $this->regw->writeAttribute($attributeChild->getKeyname(), $attributeChild->getValue()); |
| 86: | } |
| 87: | } |
| 88: | |
| 89: | foreach ($child->children as $child2) { |
| 90: | |
| 91: | if (isset($child2)) { |
| 92: | $this->regw->startElement($child2->getKeyname()); |
| 93: | if ($child2->hasattributes) { |
| 94: | foreach ($child2->attributes as $attributeChild) { |
| 95: | $this->regw->writeAttribute($attributeChild->getKeyname(), $attributeChild->getValue()); |
| 96: | } |
| 97: | } |
| 98: | |
| 99: | $this->regw->text(trim($child2->getValue())); |
| 100: | $this->regw->endElement(); |
| 101: | } |
| 102: | }$this->regw->endElement(); |
| 103: | } |
| 104: | } |
| 105: | } |
| 106: | $this->regw->endElement(); |
| 107: | } |
| 108: | } |
| 109: | } |
| 110: | } |
| 111: | $this->regw->endElement(); |
| 112: | $this->regw->endElement(); |
| 113: | $xml = $this->regw->flush(); |
| 114: | return $xml; |
| 115: | } |
| 116: | |
| 117: | function saveXml($filename, $filecontent) { |
| 118: | |
| 119: | $myfile = fopen($filename, "w") or die("Unable to open file!"); |
| 120: | |
| 121: | fwrite($myfile, $filecontent); |
| 122: | |
| 123: | fclose($myfile); |
| 124: | } |
| 125: | |
| 126: | } |
| 127: | |