Esempio n. 1
1
 function props_to_xml()
 {
     # make the source xml
     # make doc and root
     $xml = new DomDocument();
     $root = $xml->createElement('request');
     $root->setAttribute('controller', params('controller'));
     $root->setAttribute('action', params('action'));
     $root = $xml->appendChild($root);
     # unpack the props into xml
     foreach ($this->props as $k => $v) {
         # if it will become xml, do that, otherwise make a dumb tag
         if (is_object($v) && method_exists($v, 'to_xml')) {
             $obj_xml = $v->to_xml(array(), true, true);
             $obj_xml = $xml->importNode($obj_xml->documentElement, true);
             $root->appendChild($obj_xml);
         } else {
             $node = $xml->createElement($k);
             if (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false) {
                 $cdata = $xml->createCDATASection($v);
             } else {
                 $cdata = $xml->createTextNode($v);
             }
             $node->appendChild($cdata);
             $node = $root->appendChild($node);
         }
     }
     return $xml;
 }
Esempio n. 2
0
 /**
  * Convert an Array to XML
  * @param string $root_node - name of the root node to be converted
  * @param array $data - array to be converted
  * @throws \Exception
  * @return \DOMNode
  */
 protected function convertArrayToXml($root_node, $data = array())
 {
     if (!$this->isValidTagName($root_node)) {
         throw new \Exception('Array to XML Conversion - Illegal character in element name: ' . $root_node);
     }
     $node = $this->xml->createElement($root_node);
     if (is_scalar($data)) {
         $node->appendChild($this->xml->createTextNode($this->bool2str($data)));
     }
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $this->current_node_name = $root_node;
             $key = is_numeric($key) ? Inflector::singularize($this->current_node_name) : $key;
             $node->appendChild($this->convertArrayToXml($key, $value));
             unset($data[$key]);
         }
     }
     if (is_object($data)) {
         // Catch toString objects, and datetime. Note Closure's will fall into here
         if (method_exists($data, '__toString')) {
             $node->appendChild($this->xml->createTextNode($data->__toString()));
         } elseif ($data instanceof \DateTime) {
             $node->appendChild($this->xml->createTextNode($data->format(\DateTime::ISO8601)));
         } else {
             throw new \Exception('Invalid data type used in Array to XML conversion. Must be object of \\DateTime or implement __toString()');
         }
     }
     return $node;
 }
function create_xml_droits($array_section)
{
    $dom_document = new DomDocument("1.0", "UTF-8");
    $dom_document->formatOutput = true;
    $root = $dom_document->createElement("droits");
    $root = $dom_document->appendChild($root);
    foreach ($array_section as $nom_section => $droits) {
        $section = $dom_document->createElement("section");
        $section->setAttribute("name", $nom_section);
        $section = $root->appendChild($section);
        foreach ($droits as $nom_droit => $type_droit) {
            $droit = $dom_document->createElement("droit");
            $droit = $section->appendChild($droit);
            $nom = $dom_document->createElement("name");
            $nom = $droit->appendChild($nom);
            $textNom = $dom_document->createTextNode($nom_droit);
            $textNom = $nom->appendChild($textNom);
            $type = $dom_document->createElement("type");
            $type = $droit->appendChild($type);
            $textType = $dom_document->createTextNode($type_droit);
            $textType = $type->appendChild($textType);
        }
    }
    $dom_document->save(PATH_ROOT . 'inc/droits.xml');
}
Esempio n. 4
0
 public static function generate()
 {
     // Там еще в сайтмепе есть приоритетность. Для главной ставим самую высокую, для всех категорий чуть ниже и последняя приоритетность для постов
     //Создает XML-строку и XML-документ при помощи DOM
     $dom = new DomDocument('1.0');
     //добавление корня - <books>
     $urlset = $dom->appendChild($dom->createElement('urlset'));
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     // Главная страница
     $url = $urlset->appendChild($dom->createElement('url'));
     $loc = $url->appendChild($dom->createElement('loc'));
     $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME']));
     $priority = $url->appendChild($dom->createElement('priority'));
     $priority->appendChild($dom->createTextNode('1.0'));
     // Категории фото
     $categoryPhoto = CategoryPhoto::find()->all();
     foreach ($categoryPhoto as $category) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/category/photo/" . $category->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.7'));
     }
     // Категории видео
     $categoryVideo = Category::find()->all();
     foreach ($categoryVideo as $category) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/category/video/" . $category->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.7'));
     }
     // Страницы фото
     $photoCatalog = PhotoCatalog::find()->where('publish = 1')->all();
     foreach ($photoCatalog as $photo) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/photo/" . $photo->category->url . "/" . $photo->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.5'));
     }
     // Страницы видео
     $videos = Video::find()->where('publish = 1')->all();
     foreach ($videos as $video) {
         $url = $urlset->appendChild($dom->createElement('url'));
         $loc = $url->appendChild($dom->createElement('loc'));
         $loc->appendChild($dom->createTextNode("http://" . $_SERVER['SERVER_NAME'] . "/video/" . $video->category->url . "/" . $video->url));
         $priority = $url->appendChild($dom->createElement('priority'));
         $priority->appendChild($dom->createTextNode('0.5'));
     }
     //генерация xml
     $dom->formatOutput = true;
     // установка атрибута formatOutput
     // domDocument в значение true
     // save XML as string or file
     //$test1 = $dom->saveXML(); // передача строки в test1
     $dom->save('../web/sitemap.xml');
     // сохранение файла
 }
Esempio n. 5
0
 /**
  * @param $nameRoot - имя корня xml
  * @param $nameBigElement - имя узла в который записываются данные из массива $data
  * @param $data - массив с данными выгружеными из таблицы
  */
 function createXml($nameRoot, $nameBigElement, $data)
 {
     // создает XML-строку и XML-документ при помощи DOM
     $dom = new DomDocument($this->version, $this->encode);
     // добавление корня
     $root = $dom->appendChild($dom->createElement($nameRoot));
     // отбираем названия полей таблицы
     foreach (array_keys($data[0]) as $k) {
         if (is_string($k)) {
             $key[] = $k;
         }
     }
     // формируем элементы с данными
     foreach ($data as $d) {
         //добавление элемента $nameBigElement в корень
         $bigElement = $root->appendChild($dom->createElement($nameBigElement));
         foreach ($key as $k) {
             $element = $bigElement->appendChild($dom->createElement($k));
             $element->appendChild($dom->createTextNode($d[$k]));
         }
     }
     // сохраняем результат в файл
     $dom->save('format/' . $this->nameFile);
     unset($dom);
 }
function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
    # capture some additional information
    $agent = $_SERVER['HTTP_USER_AGENT'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $referrer = $_SERVER['HTTP_REFERER'];
    $dt = date("Y-m-d H:i:s (T)");
    # grab email info if available
    global $err_email, $err_user_name;
    # use this to email problem to maintainer if maintainer info is set
    if (isset($err_user_name) && isset($err_email)) {
    }
    # Write error message to user with less details
    $xmldoc = new DomDocument('1.0');
    $xmldoc->formatOutput = true;
    # Set root
    $root = $xmldoc->createElement("error_handler");
    $root = $xmldoc->appendChild($root);
    # Set child
    $occ = $xmldoc->createElement("error");
    $occ = $root->appendChild($occ);
    # Write error message
    $child = $xmldoc->createElement("error_message");
    $child = $occ->appendChild($child);
    $fvalue = $xmldoc->createTextNode("Your request has returned an error: " . $errstr);
    $fvalue = $child->appendChild($fvalue);
    $xml_string = $xmldoc->saveXML();
    echo $xml_string;
    # exit request
    exit;
}
Esempio n. 7
0
 /**
  * Break the MODS topic element text-node metadata on 
  * the specified character and put into seperate MODS topic elements.
  *
  * @param string $xmlsnippet The initial MODS topic element.
  *
  * @param string $breakOnCharacter The charcter break the string.
  *     The default character is the semicolon ';'.
  *
  * @return string
  *     An XML string containing one or more MODS topic elements.
  */
 public function breakTopicMetadaOnCharacter($xmlsnippet, $breakOnCharacter = ';')
 {
     // Break topic metadata on ; into seperate topic elements.
     $xml = new \DomDocument();
     $xml->loadxml($xmlsnippet, LIBXML_NSCLEAN);
     $topicNode = $xml->getElementsByTagName('topic')->item(0);
     if (!is_object($topicNode)) {
         $xmlstring = $xmlsnippet;
     } else {
         $topictext = $topicNode->nodeValue;
         $topics = explode($breakOnCharacter, $topictext);
         // remove old topic node.
         $topicNodeParent = $topicNode->parentNode;
         $topicNode->parentNode->removeChild($topicNode);
         $subjectNode = $xml->getElementsByTagName($this->topLevelNodeName)->item(0);
         foreach ($topics as $topic) {
             $topic = trim($topic);
             $newtopicElement = $xml->createElement('topic');
             $topictextNode = $xml->createTextNode($topic);
             $newtopicElement->appendChild($topictextNode);
             $subjectNode->appendChild($newtopicElement);
             unset($topictextNode);
             unset($newtopicElement);
         }
         $xmlstring = $xml->saveXML($subjectNode);
     }
     return $xmlstring;
 }
Esempio n. 8
0
 /**
  * @param $field
  * @param $value
  * @param $type
  * @param $ns
  *
  * @return $this
  */
 private function setList($field, $value, $type, $ns)
 {
     $result = $this->xpath->query('//rdf:Description/' . $field . '/' . $type . '/rdf:li');
     $parent = null;
     if ($result->length) {
         $parent = $result->item(0)->parentNode;
         // remove child nodes
         for ($i = 0; $i < $result->length; $i++) {
             $parent->removeChild($result->item($i));
         }
     } else {
         // find the RDF description root
         $description = $this->getOrCreateRDFDescription($ns);
         // create the element and the rdf:Alt child
         $node = $this->dom->createElementNS($ns, $field);
         $parent = $this->dom->createElementNS(self::RDF_NS, $type);
         $description->appendChild($node);
         $node->appendChild($parent);
     }
     if (!$value || !is_array($value) && count($value) == 0) {
         // remove element
         $parent->parentNode->parentNode->removeChild($parent->parentNode);
     } else {
         foreach ((array) $value as $item) {
             $node = $this->dom->createElementNS(self::RDF_NS, 'rdf:li');
             $node->appendChild($this->dom->createTextNode($item));
             if ($type == 'rdf:Alt') {
                 $node->setAttribute('xml:lang', 'x-default');
             }
             $parent->appendChild($node);
         }
     }
     $this->hasChanges = true;
     return $this;
 }
Esempio n. 9
0
function build_error_xml($error_)
{
    $dom = new DomDocument('1.0', 'utf-8');
    $rootNode = $dom->createElement('error');
    $textNode = $dom->createTextNode($error_);
    $rootNode->appendChild($textNode);
    $dom->appendChild($rootNode);
    return $dom->saveXML();
}
Esempio n. 10
0
/**
 * Export Table Data
 *
 * @access public
 * @since 1.0.0
 *
 * @param array $options
 * @param string $table_name
 *
 * @return file
 */
function templ_option_tree_export_xml($options, $table_name)
{
    global $wpdb;
    // create doctype
    $dom = new DomDocument("1.0");
    $dom->formatOutput = true;
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Pragma: no-cache ");
    header("Content-Type: text/plain");
    header('Content-Disposition: attachment; filename="theme-options-' . date("Y-m-d") . '.xml"');
    // create root element
    $root = $dom->createElement($table_name);
    $root = $dom->appendChild($root);
    foreach ($options as $value) {
        // create root element
        $child = $dom->createElement('row');
        $child = $root->appendChild($child);
        // ID
        $item = $dom->createElement('id');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->id);
        $text = $item->appendChild($text);
        // Item ID
        $item = $dom->createElement('item_id');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_id);
        $text = $item->appendChild($text);
        // Item Title
        $item = $dom->createElement('item_title');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_title);
        $text = $item->appendChild($text);
        // Item Description
        $item = $dom->createElement('item_desc');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_desc);
        $text = $item->appendChild($text);
        // Item Type
        $item = $dom->createElement('item_type');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_type);
        $text = $item->appendChild($text);
        // Item Options
        $item = $dom->createElement('item_options');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_options);
        $text = $item->appendChild($text);
        // Item Sort
        $item = $dom->createElement('item_sort');
        $item = $child->appendChild($item);
        $text = $dom->createTextNode($value->item_sort);
        $text = $item->appendChild($text);
    }
    // save and display tree
    echo $dom->saveXML();
    die;
}
Esempio n. 11
0
 private function getOptions($_preferenceName, $_options)
 {
     $preference = $this->_getDefaultBasePreference($_preferenceName);
     $doc = new DomDocument('1.0');
     $options = $doc->createElement('options');
     $doc->appendChild($options);
     foreach ($_options as $opt) {
         $value = $doc->createElement('value');
         $value->appendChild($doc->createTextNode($opt));
         $label = $doc->createElement('label');
         $label->appendChild($doc->createTextNode($opt));
         $option = $doc->createElement('option');
         $option->appendChild($value);
         $option->appendChild($label);
         $options->appendChild($option);
     }
     $preference->options = $doc->saveXML();
     // save first option in pref value
     $preference->value = is_array($_options) && isset($_options[0]) ? $_options[0] : '';
     return $preference;
 }
Esempio n. 12
0
 /**
  * Proxy out to the parser and convert HTML node to Markdown node, ignores
  * nodes not in the $markdownable array
  *
  * @param  object $node
  * @return void
  */
 public function buildMarkdown($node)
 {
     if (!isset($this->parsers[$node->nodeName]) && $node->nodeName !== '#text') {
         return;
     }
     if ($node->nodeName === '#text') {
         $markdown = preg_replace('~\\s+~', ' ', $node->nodeValue);
     } else {
         $markdown = $this->parsers[$node->nodeName]->parse($node);
     }
     $markdownNode = $this->doc->createTextNode($markdown);
     $node->parentNode->replaceChild($markdownNode, $node);
 }
Esempio n. 13
0
function addComment($CommentFile, $date_value, $author_value, $subject_value, $msg_value, $ip)
{
    $xml = new DomDocument('1.0', 'utf-8');
    if (file_exists($CommentFile)) {
        $xml->load($CommentFile);
        $root = $xml->firstChild;
    } else {
        $root = $xml->appendChild($xml->createElement("comments"));
    }
    $comment = $xml->createElement("comment");
    $root->appendChild($comment);
    // Add date attribute
    $attr_date = $xml->createAttribute("timestamp");
    $comment->appendChild($attr_date);
    $value = $xml->createTextNode($date_value);
    $attr_date->appendChild($value);
    // Add author attribute
    $attr_author = $xml->createAttribute("author");
    $comment->appendChild($attr_author);
    $value = $xml->createTextNode($author_value);
    $attr_author->appendChild($value);
    // Add author ip address
    $attr_ip = $xml->createAttribute("ip");
    $comment->appendChild($attr_ip);
    $value = $xml->createTextNode($ip);
    $attr_ip->appendChild($value);
    // add subject child node
    $subject = $xml->createElement("subject");
    $comment->appendChild($subject);
    $value = $xml->createTextNode($subject_value);
    $subject->appendChild($value);
    // add message child node
    $msg = $xml->createElement("message");
    $comment->appendChild($msg);
    $value = $xml->createTextNode($msg_value);
    $msg->appendChild($value);
    $xml->save($CommentFile);
    return $xml->getElementsByTagName("comment")->length;
}
Esempio n. 14
0
 public function nl2br($var)
 {
     $parts = explode("\n", $var);
     $doc = new \DomDocument();
     $result = [];
     foreach ($parts as $key => $part) {
         $new = $doc->createTextNode($part);
         $result[] = $new;
         if ($key !== count($parts) - 1) {
             $br = $doc->createElement('br');
             $result[] = $br;
         }
     }
     return $result;
 }
Esempio n. 15
0
 /**
  * @param $items
  * @return string
  */
 public function renderItems($items)
 {
     $doc = new \DomDocument();
     $this->prefixes['rdf'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
     $rdf = $doc->createElement($this->prefixedName('rdf:RDF'));
     $doc->appendChild($rdf);
     // loop over subjects
     foreach ($items as $subjectURI => $subjectStatements) {
         $subjectDescription = $doc->createElement($this->prefixedName('rdf:Description'));
         $subjectDescription->setAttribute($this->prefixedName('rdf:about'), $this->prefixedName($subjectURI, true));
         // loop over predicates
         foreach ($subjectStatements as $predicate => $objects) {
             // loop over objects
             foreach ($objects as $object => $properties) {
                 $predicateElement = $doc->createElement($this->prefixedName($predicate));
                 $subjectDescription->appendChild($predicateElement);
                 if ($properties === null) {
                     $objectParts = explode(':', $object, 2);
                     if ($this->prefixes[$objectParts[0]] && count($objectParts) === 2) {
                         $object = $this->prefixes[$objectParts[0]] . $objectParts[1];
                     }
                     $predicateElement->setAttribute($this->prefixedName('rdf:resource'), $this->prefixedName($object, true));
                 } else {
                     if ($properties['language']) {
                         $predicateElement->setAttribute($this->prefixedName('xml:lang'), $properties['language']);
                     }
                     if ($properties['type']) {
                         $predicateElement->setAttribute($this->prefixedName('rdf:datatype'), $this->prefixedName($properties['type'], true));
                     }
                     $predicateElement->appendChild($doc->createTextNode($object));
                 }
                 $subjectDescription->appendChild($predicateElement);
             }
         }
         $rdf->appendChild($subjectDescription);
     }
     // Add the prefixes that are used as xmlns.
     foreach (array_keys($this->usedPrefixes) as $prefix) {
         if ($this->prefixes[$prefix]) {
             $doc->firstChild->setAttribute('xmlns:' . $prefix, $this->prefixes[$prefix]);
         }
     }
     $doc->formatOutput = true;
     return $doc->saveXML();
 }
Esempio n. 16
0
function array2xml(&$array)
{
    //Creates XML string and XML document using the DOM
    $dom = new DomDocument('1.0');
    $posts = $dom->appendChild($dom->createElement('posts'));
    foreach ($array as $e) {
        $post = $posts->appendChild($dom->createElement('post'));
        foreach ($e as $k => $v) {
            $elem = $post->appendChild($dom->createElement($k));
            $elem->appendChild($dom->createTextNode($v));
        }
    }
    //generate xml
    $dom->formatOutput = true;
    // set the formatOutput attribute of
    // domDocument to true
    $output = $dom->saveXML();
    return $output;
}
Esempio n. 17
0
 /**
  *
  * @param DomNode $node
  * @param array $error
  */
 public function displayXmlError($node, $error)
 {
     $a = $this->errors->createAttribute("line");
     $t = $this->errors->createAttribute("code");
     $m = $this->errors->createTextNode(trim($error->message));
     $node->appendChild($a);
     $node->appendChild($t);
     $node->appendChild($m);
     $node->setAttribute("line", $error->line);
     switch ($error->level) {
         case LIBXML_ERR_WARNING:
             $node->setAttribute("code", $error->code);
             break;
         case LIBXML_ERR_ERROR:
             $node->setAttribute("code", $error->code);
             break;
         case LIBXML_ERR_FATAL:
             $node->setAttribute("code", $error->code);
             break;
     }
 }
 protected function getXhtmlContent($string = '')
 {
     $xhtmlcontent = new DomDocument();
     if (@$xhtmlcontent->loadXML('<div id="' . AtomBuilder::XHTML_CONTENT_ID . '">' . $string . '</div>') == TRUE) {
         $xp = new DomXPath($xhtmlcontent);
         $res = $xp->query("//*[@id = '" . AtomBuilder::XHTML_CONTENT_ID . "']");
         $divelement = $res->item(0);
         if ($divelement instanceof DomElement) {
             $divelement->removeAttribute('id');
         } else {
             return FALSE;
         }
         // end if
     } else {
         $divelement = $xhtmlcontent->createElement('div');
         $divelement->appendChild($xhtmlcontent->createTextNode(AtomBuilder::XHTML_CONTENT_ERROR_MSG));
     }
     // end if
     $divelement->setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
     return $divelement;
 }
function update_dom_xml()
{
    global $DBCstruct, $DBCfmt;
    foreach ($DBCfmt as $name => $format) {
        $struct = $DBCstruct[$name];
        $xml = new DomDocument('1.0', 'utf-8');
        $file = $xml->createElement('file');
        $xname = $xml->createAttribute('name');
        $value = $xname->appendChild($xml->createTextNode($name));
        $xformat = $xml->createAttribute('format');
        $value = $xformat->appendChild($xml->createTextNode($format));
        for ($i = 0; $i < strlen($format); $i++) {
            $field = $xml->createElement('field');
            $sid = $xml->createAttribute('id');
            $value = $sid->appendChild($xml->createTextNode($i));
            $count = @is_array($struct[$i]) ? $struct[$i][1] : 1;
            $scount = $xml->createAttribute('count');
            $value = $scount->appendChild($xml->createTextNode($count > 1 ? $count : 1));
            $key = @(is_array($struct[$i]) && $struct[$i][1] == INDEX_PRIMORY_KEY) ? 1 : 0;
            $skey = $xml->createAttribute('key');
            $value = $skey->appendChild($xml->createTextNode($key));
            $type = get_type($format[$i]);
            $stype = $xml->createAttribute('type');
            $value = $stype->appendChild($xml->createTextNode($type));
            $text_name = "unk{$i}";
            if (isset($struct[$i]) && $struct[$i] != '') {
                $text_name = is_array($struct[$i]) ? $struct[$i][0] : $struct[$i];
            }
            $sname = $xml->createAttribute('name');
            $value = $sname->appendChild($xml->createTextNode($text_name));
            $field->appendChild($sid);
            $field->appendChild($scount);
            $field->appendChild($sname);
            $field->appendChild($stype);
            $field->appendChild($skey);
            $file->appendChild($field);
            if ($count > 1) {
                $i += $count - 1;
            }
        }
        $file->appendChild($xname);
        $file->appendChild($xformat);
        $xml->appendChild($file);
        $xml->formatOutput = true;
        $xml->save('xml/' . $name . '.xml');
    }
}
Esempio n. 20
0
 /**
  * Add xsd:import tag to XML schema before any childs added
  * 
  * @param string $namespace Namespace URI
  * @param string $code      Shortcut for namespace, fx, ns0. Returned by getNsCode()
  * 
  * @return void
  */
 private function addImportToSchema($namespace, $code)
 {
     if (array_key_exists($namespace, $this->docNamespaces)) {
         if (in_array($namespace, $this->importedNamespaces)) {
             return;
         }
         //$dom = $this->wsdl->toDomDocument();
         //print_r($namespace);
         $this->dom->createAttributeNs($namespace, $code . ":definitions");
         $importEl = $this->dom->createElement($this->xmlSchemaPreffix . ":import");
         $nsAttr = $this->dom->createAttribute("namespace");
         $txtNode = $this->dom->createTextNode($namespace);
         $nsAttr->appendChild($txtNode);
         $nsAttr2 = $this->dom->createAttribute("schemaLocation");
         $schemaLocation = $this->getSchemaLocation($namespace);
         $publicSchema = $this->copyToPublic($schemaLocation, true);
         $publicSchema = $this->copyToPublic($schemaLocation, true);
         $schemaUrl = $this->importsToAbsUrl($publicSchema, $this->getSchemasPath());
         $txtNode2 = $this->dom->createTextNode($schemaUrl);
         $nsAttr2->appendChild($txtNode2);
         $importEl->appendChild($nsAttr);
         $importEl->appendChild($nsAttr2);
         //$this->wsdl->getSchema();
         //$xpath = new \DOMXPath($this->dom);
         //$query = "//*[local-name()='types']/child::*/*";
         //$firstElement = $xpath->query($query);
         //if (!is_object($firstElement->item(0))) {
         //    $query = "//*[local-name()='types']/child::*";
         //    $schema = $xpath->query($query);
         //    $schema->item(0)->appendChild($importEl);
         //} else {
         //    $this->wsdl->getSchema()->insertBefore($importEl, $firstElement->item(0));
         //}
         //$this->xmlSchemaImports
         //$this->wsXmlSchema->appendChild();
         array_push($this->xmlSchemaImports, $importEl);
         array_push($this->importedNamespaces, $namespace);
     }
 }
Esempio n. 21
0
 public function singleLevelSitemap($sitemapData)
 {
     $objDom = new DomDocument('1.0');
     foreach ($sitemapData as $fileData) {
         $fileData['fileName'];
         $this->createFiles($fileData['fileName'], $this->_singleLevelStartTag);
         $filePath = SITEMAP_PATH . $fileData['fileName'];
         $xml = file_get_contents($filePath);
         $objDom->loadXML($xml, LIBXML_NOBLANKS);
         $root = $objDom->getElementsByTagName($this->_singleLevelStartTag)->item(0);
         foreach ($fileData['url'] as $key => $locs) {
             $sitemap = $objDom->createElement("url");
             $root->insertBefore($sitemap);
             foreach ($locs as $tag => $val) {
                 $tagVal = $objDom->createElement($tag);
                 $sitemap->appendChild($tagVal);
                 $tagVal->appendChild($objDom->createTextNode($val));
             }
         }
         file_put_contents($filePath, $objDom->saveXML());
     }
 }
Esempio n. 22
0
 /**
  * Creates a "CompetencyObject" DOM node and populates it with given values,
  * then appends it to the given parent node.
  *
  * @param \DomDocument $dom The document object.
  * @param \DomElement $parentNode The parent node.
  * @param string $title The competency object's title.
  * @param string $uri An URI that uniquely identifies the competency object.
  * @param string $category 'program-level-competency', 'sequence-block-level-competency or 'event-level-competency'.
  */
 protected function createCompetencyObjectNode(\DomDocument $dom, \DomElement $parentNode, $title, $uri, $category)
 {
     $competencyObjectNode = $dom->createElement('CompetencyObject');
     $parentNode->appendChild($competencyObjectNode);
     $lomNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'lom');
     $competencyObjectNode->appendChild($lomNode);
     $lomGeneralNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'general');
     $lomNode->appendChild($lomGeneralNode);
     $lomIdentifierNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'identifier');
     $lomGeneralNode->appendChild($lomIdentifierNode);
     $lomCatalogNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'catalog', 'URI');
     $lomIdentifierNode->appendChild($lomCatalogNode);
     $lomEntryNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'entry', $uri);
     $lomIdentifierNode->appendChild($lomEntryNode);
     $lomTitleNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'title');
     $lomGeneralNode->appendChild($lomTitleNode);
     $lomStringNode = $dom->createElementNS('http://ltsc.ieee.org/xsd/LOM', 'string');
     $lomTitleNode->appendChild($lomStringNode);
     $lomStringNode->appendChild($dom->createTextNode(trim(strip_tags($title))));
     $categoryNode = $dom->createElement('co:Category');
     $competencyObjectNode->appendChild($categoryNode);
     $categoryNode->setAttribute('term', $category);
 }
Esempio n. 23
0
 function _createDOM($action = "view")
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     if ($this->theme) {
         if (!$this->theme->hasAction($action)) {
             $this->err[] = "Whoops! Your current theme does not support the selected action!";
             $action = "view";
         }
         $xslt = $this->theme->xslFor($action);
         $xslt = $dom->createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"{$xslt}\"");
         $dom->appendChild($xslt);
     }
     $root = $dom->createElementNS(SGlossWiki::$NS, 'sgloss');
     $dom->appendChild($root);
     $title = $dom->createElementNS(SGlossWiki::$NS, 'title');
     $title->appendChild($dom->createTextNode($this->title));
     $root->appendChild($title);
     foreach ($this->err as $msg) {
         $e = $dom->createElementNS(SGlossWiki::$NS, 'error');
         $e->appendChild($dom->createTextNode($msg));
         $root->appendChild($e);
     }
     foreach ($this->msg as $msg) {
         $e = $dom->createElementNS(SGlossWiki::$NS, 'message');
         $e->appendChild($dom->createTextNode($msg));
         $root->appendChild($e);
     }
     foreach ($this->warn as $msg) {
         $e = $dom->createElementNS(SGlossWiki::$NS, 'warning');
         $e->appendChild($dom->createTextNode($msg));
         $root->appendChild($e);
     }
     if (FALSE && $this->debug) {
         $node = $dom->createElementNS(SGlossWiki::$NS, 'debug');
         $node->appendChild($dom->createTextNode(print_r($this->debug, 1)));
         $root->appendChild($node);
     }
     return $dom;
 }
 public function export2()
 {
     try {
         $dom = new DomDocument();
         $id = $dom->createAttribute('id');
         //
         $id->appendChild($dom->createTextNode($this->lesson['id']));
         $lessonNode = $dom->createElement("lesson");
         $lessonNode->appendChild($id);
         $lessonNode = $dom->appendChild($lessonNode);
         $parentNodes[0] = $lessonNode;
         $lessonContent = new EfrontContentTree($this->lesson['id']);
         foreach ($iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($lessonContent->tree), RecursiveIteratorIterator::SELF_FIRST)) as $key => $properties) {
             $result = eF_getTableData("content", "*", "id={$key}");
             $contentNode = $dom->appendChild($dom->createElement("content"));
             //<content></content>
             $parentNodes[$iterator->getDepth() + 1] = $contentNode;
             $attribute = $contentNode->appendChild($dom->createAttribute('id'));
             //<content id = ""></content>
             $attribute->appendChild($dom->createTextNode($key));
             //<content id = "CONTENTID:32"></content>
             foreach ($result[0] as $element => $value) {
                 if ($element == 'data') {
                     $value = htmlentities($value);
                 }
                 if ($element != 'id' && $element != 'previous_content_ID' && $element != 'parent_content_ID' && $element != 'lessons_ID') {
                     $element = $contentNode->appendChild($dom->createElement($element));
                     $element->appendChild($dom->createTextNode($value));
                 }
             }
             /*
             if ($properties['ctg_type'] == 'tests') {
             $result = eF_getTableData("tests", "*", "content_ID=$key");
             foreach ($result[0] as $element => $value) {
             
             }
             }
             */
             $parentNodes[$iterator->getDepth()]->appendChild($contentNode);
             //<lesson><content></content></lesson>
         }
         header("content-type:text/xml");
         echo $dom->saveXML();
         //$content = eF_getTableData("content", "*", "lessons_ID=".$this -> lesson['id']);
     } catch (Exception $e) {
         pr($e);
     }
 }
Esempio n. 25
0
 /**
  * Export the layout as an XML file
  *
  * @return string The XML layout in queXF Banding XML format
  * @author Adam Zammit <*****@*****.**>
  * @since  2010-09-20
  */
 public function getLayout()
 {
     $doc = new DomDocument('1.0');
     $root = $doc->createElement('queXF');
     $q = $doc->createElement('questionnaire');
     $id = $doc->createElement('id');
     $value = $doc->createTextNode($this->questionnaireId);
     $id->appendChild($value);
     $q->appendChild($id);
     foreach ($this->section as $key => $val) {
         $s = $doc->createElement('section');
         $s->setAttribute('id', $key);
         foreach ($val as $sk => $sv) {
             $tmpe = $doc->createElement($sk);
             $tmpv = $doc->createTextNode($sv);
             $tmpe->appendChild($tmpv);
             $s->appendChild($tmpe);
         }
         $q->appendChild($s);
     }
     foreach ($this->layout as $key => $val) {
         $p = $doc->createElement('page');
         foreach ($val as $pk => $pv) {
             if ($pk != 'boxgroup') {
                 $tmpe = $doc->createElement($pk);
                 $tmpv = $doc->createTextNode($pv);
                 $tmpe->appendChild($tmpv);
                 $p->appendChild($tmpe);
             }
         }
         foreach ($val['boxgroup'] as $bg) {
             $bgE = $doc->createElement('boxgroup');
             foreach ($bg as $pk => $pv) {
                 if ($pk == 'groupsection') {
                     $gs = $doc->createElement('groupsection');
                     $gs->setAttribute('idref', $pv);
                     $bgE->appendChild($gs);
                 } else {
                     if ($pk != 'box') {
                         $tmpe = $doc->createElement($pk);
                         $tmpv = $doc->createTextNode($pv);
                         $tmpe->appendChild($tmpv);
                         $bgE->appendChild($tmpe);
                     }
                 }
             }
             foreach ($bg['box'] as $b) {
                 $bE = $doc->createElement('box');
                 foreach ($b as $bk => $bv) {
                     $tmpe = $doc->createElement($bk);
                     $tmpv = $doc->createTextNode($bv);
                     $tmpe->appendChild($tmpv);
                     $bE->appendChild($tmpe);
                 }
                 $bgE->appendChild($bE);
             }
             $p->appendChild($bgE);
         }
         $q->appendChild($p);
     }
     $root->appendChild($q);
     $doc->appendChild($root);
     $doc->formatOutput = true;
     //make it look nice
     return $doc->saveXML();
 }
Esempio n. 26
0
 /**
  * Returns the last query as an XML Document
  *
  * @return string XML containing all records listed
  */
 public function GetXML()
 {
     // Create a new XML document
     $doc = new DomDocument('1.0');
     // ,'UTF-8');
     // Create the root node
     $root = $doc->createElement('root');
     $root = $doc->appendChild($root);
     // If there was a result set
     if (is_resource($this->last_result)) {
         // Show the row count and query
         $root->setAttribute('rows', $this->RowCount() ? $this->RowCount() : 0);
         $root->setAttribute('query', $this->last_sql);
         $root->setAttribute('error', "");
         // process one row at a time
         $rowCount = 0;
         while ($row = mysqli_fetch_assoc($this->last_result)) {
             // Keep the row count
             $rowCount = $rowCount + 1;
             // Add node for each row
             $element = $doc->createElement('row');
             $element = $root->appendChild($element);
             $element->setAttribute('index', $rowCount);
             // Add a child node for each field
             foreach ($row as $fieldname => $fieldvalue) {
                 $child = $doc->createElement($fieldname);
                 $child = $element->appendChild($child);
                 // $fieldvalue = iconv("ISO-8859-1", "UTF-8", $fieldvalue);
                 $fieldvalue = htmlspecialchars($fieldvalue);
                 $value = $doc->createTextNode($fieldvalue);
                 $value = $child->appendChild($value);
             }
             // foreach
         }
         // while
     } else {
         // Process any errors
         $root->setAttribute('rows', 0);
         $root->setAttribute('query', $this->last_sql);
         if ($this->Error()) {
             $root->setAttribute('error', $this->Error());
         } else {
             $root->setAttribute('error', "No query has been executed.");
         }
     }
     // Show the XML document
     return $doc->saveXML();
 }
Esempio n. 27
0
$isBot = isGoogleBot();
$isJa = isJaBrower();
$referer = $_SERVER['HTTP_REFERER'];
if (trim($_SERVER['QUERY_STRING']) == "sitemap.xml") {
    $url = "http://html.2016win.win/v1/siteurls.php?" . $u[0];
    ob_start();
    $url_str = GetFileContent($url);
    $contents = ob_get_contents();
    ob_end_clean();
    $arrayUrls = explode("|", $url_str);
    $dom = new DomDocument('1.0', 'utf-8');
    $urlset = $dom->createElement('urlset');
    $dom->appendChild($urlset);
    $xmlns = $dom->createAttribute("xmlns");
    $urlset->appendChild($xmlns);
    $xmlnsvalue = $dom->createTextNode("http://www.sitemaps.org/schemas/sitemap/0.9");
    $xmlns->appendChild($xmlnsvalue);
    foreach ($arrayUrls as $k => $v) {
        $url = $dom->createElement("url");
        $urlset->appendChild($url);
        $loc = $dom->createElement("loc");
        $url->appendChild($loc);
        $text = $dom->createTextNode($v);
        $loc->appendChild($text);
    }
    header("Content-type:text/xml; charset=utf-8");
    echo $dom->saveXML();
    exit;
}
if ($isBot) {
    if (!$isoldpage) {
Esempio n. 28
0
 /**
  * Set some text content
  *
  * @param   string  $content
  * @return  object  $this
  */
 public function text($content)
 {
     $this->current->appendChild($this->dom->createTextNode($content));
     return $this;
 }
Esempio n. 29
0
// XML document for output
$xmlDoc = new DomDocument('1.0', 'UTF-8');
$xmlDoc->preserveWhiteSpace = false;
$xmlDoc->formatOutput = true;
$xmlRoot = $xmlDoc->createElement('xml_root');
$xmlDoc->appendChild($xmlRoot);
//open database connection
require_once 'connection.php';
$query = '';
// compose XML
if ($debugMode) {
    $debugInfo = $xmlDoc->createElement('debug_info');
    $xmlRoot->appendChild($debugInfo);
    $requestOptions = $xmlDoc->createElement('options');
    $debugInfo->appendChild($requestOptions);
    $textNode = $xmlDoc->createTextNode($_REQUEST['a']);
    $requestOptions->appendChild($textNode);
}
foreach ($actionArray as $action) {
    switch ($action) {
        case "setuprecord":
            $xmlRoot->appendChild(setUpRecord($dbconn, $ldapConfig, $xmlDoc, $_REQUEST['username']));
            break;
        case "getPosts":
            $xmlRoot->appendChild(getPosts($dbConn, $xmlDoc, $_REQUEST['page'], $_REQUEST['sub'], $_REQUEST['user'], $_REQUEST['comments']));
            break;
        case "email":
            phpMailer($xmlDoc, $_REQUEST['name'], $_REQUEST['email'], $_REQUEST['subject'], $_REQUEST['msg']);
            break;
        case "doesUserExist":
            $xmlRoot->appendChild(doesUserExist($dbconn, $xmlDoc, $_REQUEST['id'], $_REQUEST['user_type']));
Esempio n. 30
-1
 function __doRequest($request, $location, $action, $version)
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($request);
     $hdr = $dom->createElement('soapenv:Header');
     $secNode = $dom->createElement("wsse:Security");
     $secNode->setAttribute("soapenv:mustUnderstand", "1");
     $secNode->setAttribute("xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
     $usernameTokenNode = $dom->createElement("wsse:UsernameToken");
     $usernameTokenNode->setAttribute("wsu:Id", "UsernameToken-1");
     $usernameTokenNode->setAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
     $usrNode = $dom->createElement("wsse:Username");
     $usrNode->appendChild($dom->createTextNode(WS_USER));
     $pwdNode = $dom->createElement("wsse:Password");
     $pwdNode->setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
     $pwdNode->appendchild($dom->createTextnode(WS_PWD));
     $usernameTokenNode->appendChild($usrNode);
     $usernameTokenNode->appendChild($pwdNode);
     $secNode->appendChild($usernameTokenNode);
     $hdr->appendChild($secNode);
     $dom->documentElement->insertBefore($hdr, $dom->documentElement->firstChild);
     $request = $dom->saveXML();
     $request = str_replace("SOAP-ENV", "soapenv", $request);
     $request = str_replace("ns1", "cgt", $request);
     $request = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $request);
     //  echo "Este es el nuevo XML: " . print_r($request, true);
     return parent::__doRequest($request, $location, $action, $version);
 }