You are here

public static function FeedImport::json2xml in Feed Import 7.2

Convert json object to xml.

Parameters

object: JSON object

SimpleXMLElement: XML parent

1 call to FeedImport::json2xml()
FeedImport::processJSON in ./feed_import.inc.php
Process JSON.

File

./feed_import.inc.php, line 1559
Feed import class for parsing and processing content.

Class

FeedImport
@file Feed import class for parsing and processing content.

Code

public static function json2xml(&$json, &$xml) {
  foreach ($json as $tag => &$value) {
    $tag = str_replace(' ', '_', $tag);
    if (is_object($value)) {
      if (!empty($value)) {
        $child = $xml
          ->addChild($tag);
        self::json2xml($value, $child);
      }
    }
    elseif (is_array($value)) {
      foreach ($value as &$val) {
        if (is_scalar($val)) {
          $xml
            ->addChild($tag, htmlentities($val, ENT_COMPAT, 'UTF-8', FALSE));
        }
        else {
          $child = $xml
            ->addChild($tag);
          self::json2xml($val, $child);
        }
      }
    }
    else {
      $xml
        ->addChild($tag, htmlentities($value, ENT_COMPAT, 'UTF-8', FALSE));
    }
  }
}