当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Json::fromXml方法代码示例

本文整理汇总了PHP中Zend_Json::fromXml方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Json::fromXml方法的具体用法?PHP Zend_Json::fromXml怎么用?PHP Zend_Json::fromXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Json的用法示例。


在下文中一共展示了Zend_Json::fromXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: process

 /**
  * Procesar
  */
 public function process()
 {
     foreach (glob($this->_dir_temp . "/*.kml") as $filename) {
         //convertir KML a array
         $data = Zend_Json::decode(Zend_Json::fromXml(file_get_contents($filename), false));
         $this->_findPlacemarks($data);
         $this->_findStyles($data);
         $this->_findStylesMap($data);
     }
     if (count($this->_placemarks) > 0) {
         foreach ($this->_placemarks as $key => $placemark) {
             if (isset($placemark[0])) {
                 foreach ($placemark as $elemento) {
                     $this->_procesaPunto($elemento);
                     $this->_procesaPoligono($elemento);
                     $this->_procesaMultiPoligono($elemento);
                     $this->_procesaLinea($elemento);
                     $this->_procesaMultiLinea($elemento);
                 }
             } else {
                 $this->_procesaPunto($placemark);
                 $this->_procesaPoligono($placemark);
                 $this->_procesaMultiPoligono($placemark);
                 $this->_procesaLinea($placemark);
                 $this->_procesaMultiLinea($placemark);
             }
         }
     }
     //se agregan los elementos al cache que contiene el archivo
     $cache = Cache::iniciar();
     $data = $cache->load($this->_hash);
     $data["elementos"] = $this->_elementos;
     $cache->save($data, $this->_hash);
     return $this->_elementos;
 }
开发者ID:CarlosAyala,项目名称:midas-codeigniter-modulo-emergencias,代码行数:38,代码来源:Kml_descomponer.php

示例2: _loadKml

 /**
  * Carga el KML desde sidco
  * @return type
  */
 protected function _loadKml()
 {
     $zfClient = new Zend_Http_Client($this->_kml_path);
     $zfClient->setConfig(array('timeout' => 45));
     $zfClient->setMethod(Zend_Http_Client::GET);
     $kml = json_decode(Zend_Json::fromXml($zfClient->request()->getBody()));
     return $kml;
 }
开发者ID:CarlosAyala,项目名称:midas-codeigniter-modulo-emergencias,代码行数:12,代码来源:mapa_sidco.php

示例3: unserialize

 /**
  * Deserialize XML to PHP value
  *
  * @param  string $json
  * @param  array $opts
  * @return mixed
  */
 public function unserialize($xml, array $opts = array())
 {
     try {
         $json = Zend_Json::fromXml($xml);
         return (array) Zend_Json::decode($json, Zend_Json::TYPE_OBJECT);
     } catch (Exception $e) {
         require_once 'Zend/Serializer/Exception.php';
         throw new Zend_Serializer_Exception('Unserialization failed by previous error', 0, $e);
     }
 }
开发者ID:kariachintan,项目名称:projects,代码行数:17,代码来源:Xml.php

示例4: direct

 public function direct($xmlDoc)
 {
     $request = $this->getRequest();
     $response = new Zend_Controller_Response_Http();
     $responseFormat = $request->getParam("responseformat", "xml");
     $xmlDoc->encoding = "utf-8";
     $xml = $xmlDoc->saveXML();
     if ($responseFormat == 'json') {
         echo Zend_Json::fromXml($xml, false);
     } else {
         echo $xml;
     }
 }
开发者ID:henvic,项目名称:MediaLab,代码行数:13,代码来源:PrintResponse.php

示例5: _render

 protected function _render($xml)
 {
     if ('json' == $this->_format) {
         header("Content-type: text/javascript;");
         echo Zend_Json::fromXml($xml, true);
     } else {
         header("Content-type: text/xml;");
         echo $xml;
     }
     exit;
 }
开发者ID:joegeck,项目名称:cerb4,代码行数:11,代码来源:App.php

示例6: getPack

 /**
  * Retourne un tableau contenant l'opportunité depuis le code dans pi_flexform
  */
 private function getPack()
 {
     $dataXML = Zend_Json::fromXml($this->cObj->data['pi_flexform']);
     $dataFlexform = Zend_Json::decode($dataXML, Zend_Json::TYPE_ARRAY);
     $packCode = $dataFlexform["T3FlexForms"]["data"]["sheet"]["language"]["field"]["value"];
     $subUrl = "opportunity/code/" . $packCode;
     $data = $this->getDataJson($subUrl);
     $data["Code"] = $packCode;
     return $data;
 }
开发者ID:r1zib,项目名称:typo3,代码行数:13,代码来源:class.user_azelizsalesforcepacks_pi1.php

示例7: testJsonAndXmlOutputEquivalentData

 public function testJsonAndXmlOutputEquivalentData()
 {
     $this->dispatch('/ot/api/json/?method=describe');
     $this->assertResponseCode(200);
     $this->assertNotRedirect();
     $this->assertModule('ot');
     $this->assertController('api');
     $this->assertAction('json');
     $jsonResponseObject = $this->response->outputBody();
     $this->_response = null;
     // clear the response, so the xml that we grab next doesn't have json before it.
     $this->dispatch('/ot/api/xml/?method=describe');
     $this->assertResponseCode(200);
     $this->assertNotRedirect();
     $this->assertModule('ot');
     $this->assertController('api');
     $this->assertAction('xml');
     // this might make this test useless....:
     $xmlResponseObject = Zend_Json::fromXml($this->response->outputBody());
     $this->assertEquals($jsonResponseObject, $xmlResponseObject);
 }
开发者ID:ncsuwebdev,项目名称:otframework,代码行数:21,代码来源:ApiControllerTest.php

示例8: EncodeXml

 /**
  * Encode Json From xml
  *
  * @param String $xml
  * @return String
  */
 public static function EncodeXml($xml)
 {
     return Zend_Json::fromXml($xml);
 }
开发者ID:rocknoon,项目名称:TCVM,代码行数:10,代码来源:Json.php

示例9: testUsingXML6

    /**
     * xml2json Test 6
     * It tests the conversion of demo application xml into Json format.
     *
     * XML characteristic to be tested: XML containing a large CDATA.
     *
     */
    public function testUsingXML6()
    {
        // Set the XML contents that will be tested here.
        $xmlStringContents = <<<EOT
<?xml version="1.0"?>
<demo>
    <application>
        <name>Killer Demo</name>
    </application>

    <author>
        <name>John Doe</name>
    </author>

    <platform>
        <name>LAMP</name>
    </platform>

    <framework>
        <name>Zend</name>
    </framework>

    <language>
        <name>PHP</name>
    </language>

    <listing>
        <code>
            <![CDATA[
/*
It may not be a syntactically valid PHP code.
It is used here just to illustrate the CDATA feature of Zend_Xml2Json
*/
<?php
include 'example.php';
new SimpleXMLElement();
echo(getMovies()->movie[0]->characters->addChild('character'));
getMovies()->movie[0]->characters->character->addChild('name', "Mr. Parser");
getMovies()->movie[0]->characters->character->addChild('actor', "John Doe");
// Add it as a child element.
getMovies()->movie[0]->addChild('rating', 'PG');
getMovies()->movie[0]->rating->addAttribute("type", 'mpaa');
echo getMovies()->asXML();
?>
            ]]>
        </code>
    </listing>
</demo>

EOT;
        // There are not going to be any XML attributes in this test XML.
        // Hence, set the flag to ignore XML attributes.
        $ignoreXmlAttributes = true;
        $jsonContents = "";
        $ex = null;
        // Convert XNL to JSON now.
        // fromXml function simply takes a String containing XML contents as input.
        try {
            $jsonContents = Zend_Json::fromXml($xmlStringContents, $ignoreXmlAttributes);
        } catch (Exception $ex) {
        }
        $this->assertSame($ex, null, "Zend_JSON::fromXml returned an exception.");
        // Convert the JSON string into a PHP array.
        $phpArray = Zend_Json::decode($jsonContents);
        // Test if it is not a NULL object.
        $this->assertNotNull($phpArray, "JSON result for XML input 6 is NULL");
        // Test for one of the expected fields in the JSON result.
        $this->assertContains("Zend", $phpArray['demo']['framework']['name'], "The framework name field converted from XML input 6 is not correct");
        // Test for one of the expected CDATA fields in the JSON result.
        $this->assertContains('echo getMovies()->asXML();', $phpArray['demo']['listing']['code'], "The CDATA code converted from XML input 6 is not correct");
    }
开发者ID:travisj,项目名称:zf,代码行数:78,代码来源:JsonXMLTest.php

示例10: makeRequest

 /**
  * Handles all GET requests to a web service
  *
  * @param   string $method Requested API method
  * @param   array  $params Array of GET parameters
  * @return  mixed  decoded response from web service
  * @throws  Bgy_Service_Geonames_Exception
  */
 public function makeRequest($method, $params = array())
 {
     $this->_rest->setUri(self::API_URI);
     $path = $method;
     $type = self::$_supportedMethods[$path]['output'];
     // Construct the path accordingly to the output type
     switch ($type) {
         case 'json':
             $path = $path . 'JSON';
             break;
         case 'xml':
             $params += array('type' => 'xml');
             break;
         default:
             /**
              * @see Bgy_Service_Geonames_Exception
              */
             require_once 'Bgy/Service/Geonames/Exception.php';
             throw new Bgy_Service_Geonames_Exception('Unknown request type');
     }
     if (null !== $this->getUsername()) {
         $params['username'] = $this->getUsername();
     }
     if (null !== $this->getToken()) {
         $params['token'] = $this->getToken();
     }
     $response = $this->_rest->restGet($path, $params);
     if (!$response->isSuccessful()) {
         /**
          * @see Bgy_Service_Geonames_Exception
          */
         require_once 'Bgy/Service/Geonames/Exception.php';
         throw new Bgy_Service_Geonames_Exception("Http client reported an error: '{$response->getMessage()}'");
     }
     $responseBody = $response->getBody();
     switch ($type) {
         case 'xml':
             $dom = new DOMDocument();
             if (!@$dom->loadXML($responseBody)) {
                 /**
                  * @see Bgy_Service_Geonames_Exception
                  */
                 require_once 'Bgy/Service/Geonames/Exception.php';
                 throw new Bgy_Service_Geonames_Exception('Malformed XML');
             }
             $jsonResult = Zend_Json::fromXml($dom->saveXML());
             break;
         case 'json':
             $jsonResult = $responseBody;
             break;
     }
     $arrayFromJson = Zend_Json::decode($jsonResult);
     if (isset(self::$_supportedMethods[$method]['root']) && null !== ($root = self::$_supportedMethods[$method]['root']) && isset($arrayFromJson[$root])) {
         $arrayFromJson = $arrayFromJson[$root];
     }
     return $arrayFromJson;
 }
开发者ID:exstas87,项目名称:bgylibrary,代码行数:65,代码来源:Geonames.php

示例11: testUsingXML8

    /**
     *  @group ZF-3257
     */
    public function testUsingXML8()
    {
        // Set the XML contents that will be tested here.
        $xmlStringContents = <<<EOT
<?xml version="1.0"?>
<a><b id="foo" />bar</a>

EOT;
        // There are not going to be any XML attributes in this test XML.
        // Hence, set the flag to ignore XML attributes.
        $ignoreXmlAttributes = false;
        $jsonContents = "";
        $ex = null;
        // Convert XML to JSON now.
        // fromXml function simply takes a String containing XML contents as input.
        try {
            $jsonContents = Zend_Json::fromXml($xmlStringContents, $ignoreXmlAttributes);
        } catch (Exception $ex) {
        }
        $this->assertSame($ex, null, "Zend_JSON::fromXml returned an exception.");
        // Convert the JSON string into a PHP array.
        $phpArray = Zend_Json::decode($jsonContents);
        // Test if it is not a NULL object.
        $this->assertNotNull($phpArray, "JSON result for XML input 1 is NULL");
        $this->assertSame("bar", $phpArray['a']['@text'], "The text element of a is not correct");
        $this->assertSame("foo", $phpArray['a']['b']['@attributes']['id'], "The id attribute of b is not correct");
    }
开发者ID:epixa,项目名称:Zend-Framework-v1-Mirror,代码行数:30,代码来源:JsonXMLTest.php

示例12: getResponseArray

 /**
  * Transfoms the response body (xml or json) into an array we can more easily
  * work with.
  *
  * @param Zend_Http_Response $response
  * @return array
  * @todo $this->_errors is populated with errors from Chargify. Should this
  *  also populate a separate errors array when we get HTTP 404s or 201s?
  */
 public function getResponseArray(Zend_Http_Response $response)
 {
     $return = array();
     $format = $this->getService()->getFormat();
     $body = $response->getBody();
     $body = trim($body);
     /**
      * return early on bad status codes
      */
     $code = $response->getStatus();
     $errorCodes = array(404, 401, 500);
     if (in_array($code, $errorCodes)) {
         $this->_errors['Crucial_Service_Chargify']['Bad status code'] = $code;
         return $return;
     }
     /**
      * Return early if we have an empty body, which we can't turn into an array
      * anyway. This happens in cases where the API returns a 404, and possibly
      * other status codes.
      */
     if (empty($body)) {
         return $return;
     }
     if ('json' == $format) {
         $return = Zend_Json::decode($body);
     }
     if ('xml' == $format) {
         $json = Zend_Json::fromXml($body);
         $return = Zend_Json::decode($json);
     }
     // set errors, if any
     if (!empty($return['errors'])) {
         $this->_errors = $return['errors'];
     }
     return $return;
 }
开发者ID:RealTimeApps,项目名称:chargify-sample-app,代码行数:45,代码来源:Abstract.php

示例13: ob_start

<?php

ob_start();
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?>
<Response>
  <Meta>
    <ExecutionTime><?php 
echo LsApi::getResponseTime();
?>
</ExecutionTime>
  </Meta>
  <Data>
    <?php 
echo $sf_content;
?>
  </Data>
</Response>
<?php 
$xml = ob_get_contents();
ob_end_clean();
echo Zend_Json::fromXml($xml);
开发者ID:silky,项目名称:littlesis,代码行数:22,代码来源:json.php

示例14: fault

 /**
  * This is method fault
  *
  * @param mixed $exception
  *        	This is a description
  * @param mixed $format
  *        	This is a description
  * @param mixed $httpCode
  *        	This is a description
  * @return mixed This is the return value description
  */
 public function fault($exception = null, $format = 'json', $httpCode = null)
 {
     $error = false;
     if ($exception instanceof OAuthException) {
         $error = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
     } else {
         if ($exception instanceof \Exception) {
             $error = ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
         } else {
             $error = ['code' => BAD_URL, 'message' => static::getError(BAD_URL)];
         }
     }
     switch ($format) {
         case 'xml':
             $errorXml = Response::error($error['code'], $error['message']);
             return $errorXml;
         case 'plain-text':
             return Response::plain($error);
         case 'json':
             $errorXml = Response::error($error['code'], $error['message'], false);
             return Zend_Json::fromXml($errorXml);
     }
 }
开发者ID:gponster,项目名称:laravel-oauth-server,代码行数:34,代码来源:Server.php

示例15: membersAction

 public function membersAction()
 {
     $page = $this->_getParam('page');
     if (!$this->_cache->test('members')) {
         $query = 'getMps';
         $output = '&output=xml';
         $key = '&key=' . self::TWFYAPIKEY;
         $twfy = self::TWFYURL . $query . $output . $key;
         $data = Zend_Json::fromXml($this->get($twfy), true);
         $data = json_decode($data);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load('members');
     }
     $data2 = array();
     foreach ($data->twfy->match as $a) {
         if (in_array($a->constituency, $this->_remove)) {
             unset($a->name);
             unset($a->person_id);
             unset($a->party);
             unset($a->constituency);
         }
         if (isset($a->name)) {
             $data2[] = array('name' => $a->name, 'person_id' => $a->person_id, 'constituency' => $a->constituency, 'party' => $a->party);
         }
     }
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($data2));
     if (isset($page) && $page != "") {
         $paginator->setCurrentPageNumber((int) $page);
     }
     $paginator->setItemCountPerPage(40)->setPageRange(10);
     if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json'))) {
         $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0));
         $this->view->data = $data;
         $members = array();
         foreach ($paginator as $k => $v) {
             $members[] = array();
             $members[$k] = $v;
         }
         $this->view->members = $members;
     } else {
         $this->view->data = $paginator;
     }
 }
开发者ID:rwebley,项目名称:Beowulf---PAS,代码行数:44,代码来源:TheyworkforyouController.php


注:本文中的Zend_Json::fromXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。