createXML() 공개 정적인 메소드

Convert an Array to XML
public static createXML ( string $node_name, array $arr = [] ) : DomDocument
$node_name string - name of the root node to be converted
$arr array - aray to be converterd
리턴 DomDocument
예제 #1
0
 protected function encode($cmd, $root = 'request')
 {
     switch ($this->encoding) {
         default:
         case self::ENC_RAW:
             //void
             break;
         case self::ENC_SERIALIZE:
             $cmd = serialize($cmd);
             break;
         case self::ENC_XML:
             try {
                 $cmd = Array2XML::createXML($root, $cmd)->saveXML();
             } catch (Exception $e) {
                 throw new Exception('Could not encode XML: ' . print_r($cmd));
             }
             break;
         case self::ENC_JSON:
             $cmd = json_encode($cmd);
             break;
     }
     //add encoding type
     $cmd = chr($this->encoding) . $cmd;
     return $cmd;
 }
 /**
  * Convert an Array to XML
  *
  * @param        $file_name
  * @param string $root_node_name - name of the root node to be converted
  * @param array  $data           - array to be converted
  *
  * @internal param $child_node_name
  * @return string
  */
 public function toXML($file_name, $root_node_name, array $data)
 {
     $xmlObj = Array2XML::createXML($root_node_name, $data);
     $xml = $xmlObj->saveXML();
     file_put_contents($file_name, $xml);
     return $xml;
 }
예제 #3
0
파일: XML.php 프로젝트: gelembjuk/webapp
 public function display()
 {
     $this->requireSettings();
     $displaydata = $this->prepareResponseStructure();
     header('Content-type: application/xml');
     $xml = \LSS\Array2XML::createXML('document', $displaydata);
     echo $xml->saveXML();
     return true;
 }
예제 #4
0
 /**
  * @param mixed $data
  * @return Response
  */
 public function sendData($data, $root = '')
 {
     if (!$root) {
         throw new \Exception('xml root empty');
     }
     $xmlDom = Array2XML::createXML($root, $this->getData());
     $headers = array('Content-Type' => 'text/xml; charset=utf-8');
     $httpResponse = $this->httpClient->post($this->getEndpoint(), $headers, $xmlDom->saveXML())->send();
     return $this->response = new Response($this, $httpResponse->getBody(true));
 }
예제 #5
0
파일: Xml.php 프로젝트: chameleonbr/apibird
 public function toFormat($data)
 {
     try {
         if (!is_int(key($data))) {
             Array2XML::init('1.0', 'UTF-8', false);
             $xml = Array2XML::createXML($this->options['root'], $data);
             return $xml->saveXML();
         } else {
             Array2XML::init('1.0', 'UTF-8', false);
             $xml = Array2XML::createXML($this->options['list'], array($this->options['root'] => $data));
             return $xml->saveXML();
         }
     } catch (\Exception $e) {
         $di = \Phalcon\DI\FactoryDefault::getDefault();
         $di['response']->internalServerError('Unable to write format.');
     }
 }
예제 #6
0
 public function render($response, array $data)
 {
     $contentType = $this->determineContentType($this->request->getHeaderLine('Accept'));
     switch ($contentType) {
         case 'text/html':
             $output = $this->renderHtml($data);
             break;
         case 'application/xml':
             $xml = Array2XML::createXML('root', $data);
             $output = $xml->saveXML();
             break;
         case 'application/json':
         default:
             $contentType = 'application/json';
             $output = json_encode($data);
             break;
     }
     $body = new Body(fopen('php://temp', 'r+'));
     $body->write($output);
     return $response->withHeader('Content-type', $contentType)->withBody($body);
 }
예제 #7
0
 /**
  * XML Conversion
  *
  * @param array $data
  *
  * @return string
  */
 public function convert($data = [])
 {
     $xml = Array2XML::createXML('xmlrequest', $data);
     return $xml->saveXML();
 }
 public static function createXmlFromArray(array $array, $rootTagName)
 {
     return Array2XML::createXML($rootTagName, $array);
 }
예제 #9
0
 public function SiteMapXMLAction(Request $request)
 {
     $logger = $this->get('logger');
     $result = array();
     $em = $this->getDoctrine()->getManager();
     $routes = $em->getRepository('NovuscomCMFBundle:Route')->findBy(array('active' => true));
     $Route = $this->get('Route');
     $Site = $this->get('Site');
     $currentAlias = $Site->getAlias();
     $alias = $currentAlias['name'];
     $prefix = 'http://' . $alias;
     $needRoutes = array('@attributes' => array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'), 'url' => array());
     $urlArray = array();
     /*
      * Страницы
      */
     $Site = $this->get('Site');
     $currentSite = $Site->getCurrentSite();
     $siteRef = $em->getReference('Novuscom\\CMFBundle\\Entity\\Site', $currentSite['id']);
     $pagesRepo = $em->getRepository('NovuscomCMFBundle:Page');
     $pages = $pagesRepo->findBy(array('site' => $siteRef));
     foreach ($pages as $p) {
         $codes = array();
         foreach ($pagesRepo->getPath($p) as $path) {
             $codes[] = $path->getUrl();
         }
         $url = implode('/', $codes);
         $url = str_replace('//', '/', $url);
         if ($p->getLvl() > 0) {
             $url = trim($url, '/');
             $url = $this->get('router')->generate('page', array('url' => $url));
         } else {
             $url = $this->get('router')->generate('cmf_page_main');
         }
         $url = $prefix . $url;
         $urlArray[] = $url;
     }
     foreach ($routes as $r) {
         $params = json_decode($r->getParams(), true);
         if ($r->getBlock() === false) {
             continue;
         }
         if ($r->getController() == 'NovuscomCMFBundle:Component:Element') {
             foreach ($r->getBlock()->getElement() as $element) {
                 if ($element->getActive() === false) {
                     continue;
                 }
                 $url = $Route->getUrl($r->getCode(), $element);
                 if ($url) {
                     $url = $prefix . $url;
                     $urlArray[] = $url;
                 }
             }
         }
         if ($r->getController() == 'NovuscomCMFBundle:Component:Section') {
             foreach ($r->getBlock()->getSection() as $section) {
                 $url = $Route->getUrl($r->getCode(), $section);
                 if ($url !== false) {
                     $url = $prefix . $url;
                     $urlArray[] = $url;
                 }
             }
         }
     }
     $urlArray = array_unique($urlArray);
     sort($urlArray);
     foreach ($urlArray as $u) {
         $needRoutes['url'][]['loc'][] = $u;
     }
     $xml = Array2XML::createXML('urlset', $needRoutes)->saveXML();
     $response = new Response();
     $response->headers->set('Content-Type', 'application/xml; charset=UTF-8');
     $response->setContent($xml);
     return $response;
 }
예제 #10
0
 /**
  * 创建payload字符串
  */
 protected function makePayload()
 {
     $this->payload['@attributes'] = ['xmlns' => 'http://mqs.aliyuncs.com/doc/v1/'];
     $class = class_basename(get_called_class());
     return Array2XML::createXML(strpos($class, 'Queue') !== false ? 'Queue' : 'Message', $this->payload)->saveXML();
 }
예제 #11
0
 /**
  * Fixes deployment.xml file
  * @param  string $content
  * @return string
  */
 public function fixXml($content)
 {
     $doc = new \DOMDocument();
     ErrorHandler::start();
     $doc->loadXML($content);
     ErrorHandler::stop(true);
     $data = \LSS\XML2Array::createArray($doc);
     $root = $doc->documentElement;
     $rootName = $root->tagName;
     $data[$rootName]['@attributes']['xmlns'] = $root->getAttribute('xmlns');
     // fix the order of the elements
     $data[$rootName] = self::fixMetaKeyOrder($data[$rootName]);
     $xml = \LSS\Array2XML::createXML($rootName, $data[$rootName]);
     return $xml->saveXML();
 }
예제 #12
0
 public function encode($object, EncoderOptions $options = null)
 {
     $arr = parent::encode($object, $options);
     return Array2XML::createXML(self::ROOT_NODE_NAME, $arr['processed']);
 }
예제 #13
0
 /**
  * Prepare xml for request
  *
  * @param string $method Method name
  * @param array $args Method arguments
  *
  * @return string XML fore request
  */
 private function prepareXmlForRequest($method, array $args)
 {
     $arrayToXml = Array2XML::createXML('request', $this->prepareArrayForConvertToXml($method, $args));
     return $arrayToXml->saveXML();
 }
예제 #14
0
파일: Message.php 프로젝트: qiuxiang/wechat
 /**
  * @return string
  */
 public function __toString()
 {
     $xml = Array2XML::createXML('xml', $this->data);
     return substr($xml->saveXML(), 39);
 }
예제 #15
0
 public function generateXml()
 {
     $xml = Array2XML::createXML('QuestionForm', $this->data);
     $xmlText = $xml->saveXML();
     return preg_replace('/FakeKey_(\\w+)_\\w{6}/', '$1', $xmlText);
 }