function startElement(&$parser, $tag, $attributes) { $this->currentData = null; switch ($tag) { case 'xs:simpleType': if ($attributes['name'] == $this->_listName) { $this->_foundRequestedList = true; } break; case 'xs:enumeration': if ($this->_foundRequestedList) { $this->_currentValue = $attributes['value']; $this->_listItems[$this->_currentValue] = array(); // initialize the array cell } break; case 'xs:documentation': if ($this->_foundRequestedList) { $this->_insideDocumentation = true; } break; } $node = new XMLNode($tag); $node->setAttributes($attributes); if (isset($this->currentNode)) { $this->currentNode->addChild($node); $node->setParent($this->currentNode); } else { $this->rootNode =& $node; } $this->currentNode =& $node; }
function startTagElement(&$parserHandle, $elementName, $attributes) { if (!isset($this->node)) { if (!isset($this->document)) { $this->document = new XMLDocument(); $this->node =& new XMLNode(); $this->node->node_type = XML_ELEMENT; $this->node->node_name = $elementName; $this->node->node_value = array(); $keys = array_keys($attributes); for ($i = 0; $i < count($keys); $i++) { $this->node->setAttribute(new XMLAttribute($keys[$i], $attributes[$keys[$i]])); } $this->document->setRootNode($this->node); } else { print "ERROR !"; } } else { $new_node = new XMLNode(); $new_node->node_type = XML_ELEMENT; $new_node->node_name = $elementName; $keys = array_keys($attributes); for ($i = 0; $i < count($keys); $i++) { $new_node->setAttribute(new XMLAttribute($keys[$i], $attributes[$keys[$i]])); } $this->node->node_value = array(); $this->node =& $this->node->appendChild($new_node); } }
/** * Constructor: * * @param string $name El nombre que tendrá el campo en el código * @param array $options Un array con las opciones, cada elemento del array, es un array asociativo, * con la clave "value" para el valor y la clave "text" para el label de la opción. */ function Select($name, $options = array()) { $xmlSel = new XMLNode("select", array("name" => $name)); foreach ($options as $opt) { $xmlOpt = new XMLNode("option", array("value" => $opt['value'])); $xmlOpt->AddNode(new TextNode($opt['text'])); $xmlSel->AddNode($xmlOpt); } $this->xmlObj =& $xmlSel; }
function &createTextNode(&$doc, $value) { $value = Core::cleanVar($value); if (is_callable(array($doc, 'createTextNode'))) { $element =& $doc->createTextNode($value); } else { $element = new XMLNode(); $element->setValue($value); } return $element; }
/** * Callback function to act as the start element handler. */ function startElement(&$parser, $tag, $attributes) { $this->currentData = null; $node = new XMLNode($tag); $node->setAttributes($attributes); if (isset($this->currentNode)) { $this->currentNode->addChild($node); $node->setParent($this->currentNode); } else { $this->rootNode =& $node; } $this->currentNode =& $node; }
function xmlEscape($value) { $escapedValue = XMLNode::xmlentities($value, ENT_NOQUOTES); if ($value !== $escapedValue) { return "<![CDATA[{$value}]]>"; } return $value; }
public function getEntities() { REST::requireRequestMethod('GET'); $db = new MySQL(); $entitiesNode = new XMLNode('entities'); foreach (Model::getEntities() as $entity) { $entityNode = new XMLNode('entity'); $entityNode->setAttribute('identifier', $entity['IDENTIFIER']); $entityNode->setAttribute('friendlyname', $entity['FRIENDLYNAME']); $entityNode->setAttribute('lat', $entity['LATITUDE']); $entityNode->setAttribute('lon', $entity['LONGITUDE']); $entityNode->setAttribute('date', strtotime($entity['DATETIME'])); $entitiesNode->addNode($entityNode); } $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($entitiesNode); REST::sendResponse(200, $xmlDoc, 'application/xml'); }
/** * Constructor. * @param $name element/tag name */ function __construct() { parent::__construct(); $this->name = '!--'; $this->parent = null; $this->attributes = array(); $this->value = null; $this->children = array(); }
function &setRootNode(&$node) { if (XMLNode::validClass($node)) { $node->setDocument($this); $node->node_level = 0; $this->root_node =& $node; } return $this->root_node; }
public function getTileUrl() { REST::requireRequestMethod('GET'); $requiredParameters = array('lat', 'lon', 'zoom'); if (Util::isValid($requiredParameters, $values, $this->params)) { extract($values); $url = "http://tile.openstreetmap.org/" . Map::getTileNumber($lat, $lon, $zoom) . ".png"; $urlNode = new XMLNode('url'); $urlNode->setAttribute('href', $url); $mapNode = new XMLNode('map'); $mapNode->setAttributes($values); $mapNode->addNode($urlNode); $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($mapNode); REST::sendResponse(200, $xmlDoc, 'application/xml'); } else { REST::sendResponse(400); } }
public function __construct($resource = null, $copy = true) { try { parent::__construct($resource, $copy); } catch (Exception $e) { parent::__construct(file_get_contents(dirname(__FILE__) . '/templates/FileMetadata.xml')); } $this->registerNS("escidocfile", "http://purl.org/escidoc/metadata/profiles/0.1/file"); $this->registerNS("dc", "http://purl.org/dc/elements/1.1/"); $this->registerNS("xsi", "http://www.w3.org/2001/XMLSchema-instance"); $this->registerNS("dcterms", "http://purl.org/dc/terms/"); }
public function getZones() { REST::requireRequestMethod('GET'); $zonesNode = new XMLNode('zones'); foreach (Model::getZones() as $zone) { $zoneNode = new XMLNode('zone'); $zoneNode->setAttribute('id', $zone['ID']); $zoneNode->setAttribute('type', $zone['TYPE']); $zoneNode->setAttribute('date', strtotime($zone['CREATED_ON'])); $zoneNode->setAttribute('deleted', $zone['DELETED_ON'] != '0000-00-00 00:00:00' ? 'true' : 'false'); $waypointsNode = new XMLNode('waypoints'); foreach (Model::getWaypoints($zone['ID']) as $waypoint) { $waypointNode = new XMLNode('waypoint'); $waypointNode->setAttribute('latitude', $waypoint['LATITUDE']); $waypointNode->setAttribute('longitude', $waypoint['LONGITUDE']); $waypointsNode->addNode($waypointNode); } $zoneNode->addNode($waypointsNode); $zonesNode->addNode($zoneNode); } $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($zonesNode); REST::sendResponse(200, $xmlDoc, 'application/xml'); }
function &MathMLNode($id = NULL) { parent::XMLNode($id); }
/** * @see PKPPageRouter::loadHandler() */ function callbackLoadHandler($hookName, $args) { $isEnabled = $this->getSetting(0, 'enabled'); if ($isEnabled) { $taskDao = DAORegistry::getDao('ScheduledTaskDAO'); // Grab the scheduled scheduled tree $scheduledTasks = $this->getSetting(0, 'crontab'); if (is_null($scheduledTasks)) { $this->_parseCrontab(); $scheduledTasks = $this->getSetting(0, 'crontab'); } foreach ($scheduledTasks as $task) { // We don't allow tasks without frequency, see _parseCronTab(). $frequency = new XMLNode(); $frequency->setAttribute(key($task['frequency']), current($task['frequency'])); $canExecute = ScheduledTaskHelper::checkFrequency($task['className'], $frequency); if ($canExecute) { // Strip off the package name(s) to get the base class name $className = $task['className']; $pos = strrpos($className, '.'); if ($pos === false) { $baseClassName = $className; } else { $baseClassName = substr($className, $pos + 1); } $taskArgs = array(); if (isset($task['args'])) { $taskArgs = $task['args']; } // There's a race here. Several requests may come in closely spaced. // Each may decide it's time to run scheduled tasks, and more than one // can happily go ahead and do it before the "last run" time is updated. // By updating the last run time as soon as feasible, we can minimize // the race window. TODO: there ought to be a safer way of doing this. $taskDao->updateLastRunTime($className, time()); // Load and execute the task import($className); $task = new $baseClassName($taskArgs); $task->execute(); } } } return false; }
/** * Parses and creates XML nodes from the __rawData property. * * @return boolean Success * @access public * @see load() */ function parse() { $this->header = trim(str_replace(a('<' . '?', '?' . '>'), a('', ''), substr(trim($this->__rawData), 0, strpos($this->__rawData, "\n")))); xml_parse_into_struct($this->__parser, $this->__rawData, $vals); $xml = new XMLNode(); $count = count($vals); for ($i = 0; $i < $count; $i++) { $data = $vals[$i]; switch ($data['type']) { case "open": $tmpXML = new XMLNode(); $tmpXML->name = $data['tag']; if (isset($data['value'])) { $tmpXML->value = $data['value']; } if (isset($data['attributes'])) { $tmpXML->attributes = $data['attributes']; } $tmpXML->setParent($xml); $ct = count($xml->children); $xml->children[$ct] = $tmpXML; $xml =& $xml->children[$ct]; break; case "close": $xml =& $xml->parent(); break; case "complete": $tmpXML = new XMLNode(); $tmpXML->name = $data['tag']; if (isset($data['value'])) { $tmpXML->value = $data['value']; } if (isset($data['attributes'])) { $tmpXML->attributes = $data['attributes']; } $tmpXML->__parent =& $xml; $xml->children[] = $tmpXML; break; case 'cdata': if (is_string($xml->value)) { $xml->value = a($xml->value, $data['value']); } else { $xml->value[] = $data['value']; } break; } } $this->children =& $xml->children; return true; }
/** * @param $output file handle to write to, or true for stdout, or null if XML to be returned as string * @return string */ function &toXml($output = null) { $nullVar = null; $out = ''; if ($this->parent === null) { // This is the root node. Output information about the document. $out .= "<?xml version=\"" . $this->getAttribute('version') . "\" encoding=\"UTF-8\"?>\n"; if ($this->getAttribute('type') != '') { if ($this->getAttribute('url') != '') { $out .= "<!DOCTYPE " . $this->getAttribute('type') . " PUBLIC \"" . $this->getAttribute('dtd') . "\" \"" . $this->getAttribute('url') . "\">"; } else { $out .= "<!DOCTYPE " . $this->getAttribute('type') . " SYSTEM \"" . $this->getAttribute('dtd') . "\">"; } } } if ($this->name !== null) { $out .= '<' . $this->name; foreach ($this->attributes as $name => $value) { $value = XMLNode::xmlentities($value); $out .= " {$name}=\"{$value}\""; } $out .= '>'; } $out .= XMLNode::xmlentities($this->value, ENT_NOQUOTES); foreach ($this->children as $child) { if ($output !== null) { if ($output === true) { echo $out; } else { fwrite($output, $out); } $out = ''; } $out .= $child->toXml($output); } if ($this->name !== null) { $out .= '</' . $this->name . '>'; } if ($output !== null) { if ($output === true) { echo $out; } else { fwrite($output, $out); } return $nullVar; } return $out; }
/** * Escape XML entities. * @param $string string */ function _escapeXmlEntities($string) { return XMLNode::xmlentities($string); }
/** * * Imports XML, defined in $resource, below position $xpathparent and overwrites * the element $xpathreplaces. * * @param string $xpathparent XPath of the parent * @param string $xpathreplaces XPath of the node that will be replaced * @param false $xpathreplaces just adds the resource below xpathparent * @param XMLNode $resource resource to import * @param null $resource delete resource at position $xpathreplaces */ protected function importResource($xpathparent, $resource, $xpathreplaces = false) { if (is_a($resource, "XMLNode")) { $newcontent = $resource; } else { if ($resource == null && is_string($xpathreplaces)) { $newcontent = null; } else { $newcontent = new XMLNode($resource, false); } } $parentnodes = $this->xpath($xpathparent, $this->resource); if ($parentnodes->length != 1) { throw new Exception("Ambiguous position for new resource! Found " . $parentnodes->length . " possible parent nodes."); } $parent = $parentnodes->item(0); $oldnode = false; if ($xpathreplaces != false) { $childnodes = $this->xpath($xpathreplaces, $this->resource); if ($childnodes->length > 1) { throw new Exception("Ambiguous replace position for new resource! Found " . $childnodes->length . " possible nodes."); } else { if ($childnodes->length == 1) { $oldnode = $childnodes->item(0); } } } //newcontent is null -> remove the subtree if ($newcontent == null) { if ($oldnode) { $parent->removeChild($oldnode); } return; } //Do nothing, if a node should be replaced by itself. Due to referencing this can happen. if ($oldnode !== false && $oldnode->isSameNode($newcontent->getRootNode())) { return; } $newnode = $this->dom->importNode($newcontent->getRootNode(), true); if ($oldnode) { $parent->replaceChild($newnode, $oldnode); } else { $parent->appendChild($newnode); } }
/** * Get all scheduled tasks that needs to be executed. * @return array */ function _getTasksToRun() { $tasksToRun = array(); $isEnabled = $this->getSetting(0, 'enabled'); if ($isEnabled) { $taskDao =& DAORegistry::getDao('ScheduledTaskDAO'); // Grab the scheduled scheduled tree $scheduledTasks = $this->getSetting(0, 'crontab'); if (is_null($scheduledTasks)) { $this->_parseCrontab(); $scheduledTasks = $this->getSetting(0, 'crontab'); } foreach ($scheduledTasks as $task) { // We don't allow tasks without frequency, see _parseCronTab(). $frequency = new XMLNode(); $frequency->setAttribute(key($task['frequency']), current($task['frequency'])); $canExecute = ScheduledTaskHelper::checkFrequency($task['className'], $frequency); if ($canExecute) { $tasksToRun[] = $task; } } } return $tasksToRun; }
function &appendChild(&$newChild) { //Appends the node newChild at the end of the child nodes for this node if (XMLNode::validClass($newChild)) { // set current document $newChild->node_level = $this->node_level + 1; $newChild->setDocument($this->getDocument()); // no child if (!isset($this->child)) { $newChild->parent_node =& $this; $this->child =& $newChild; } else { // get last child $child =& $this->child; while (isset($child->sibling)) { $child =& $child->sibling; } $newChild->parent_node =& $this; $newChild->previous_sibling =& $child; $child->sibling =& $newChild; } } return $newChild; }
<?php require_once 'config.inc.php'; $router = new Router($_SERVER['REQUEST_URI']); try { $router->connect(); } catch (Exception $e) { $errorNode = new XMLNode('error'); $errorNode->setAttributes(array('code' => 400)); $errorNode->setContent($e->getMessage()); $xmlDoc = new XMLDocument(); $xmlDoc->setRootNode($errorNode); echo strval($xmlDoc); }
function toString(){ $parrafo = new XMLNode("p"); foreach($this->inputs as $inp){ $parrafo->AddNode(new TextNode($inp->inputText."<br/>")); $input = new Input($inp->inputName); $parrafo->AddNode($input); $parrafo->AddNode(new TextNode("<br/>")); } $anchor = new Anchor($this->submitText); $go = new Go($this->goTo); foreach($this->inputs as $inp){ $pf_ser = new PostField($inp->postName,"$(".$inp->inputName.")"); $go->AddComponent($pf_ser); } foreach($this->vars as $var){ $pf_ser = new PostField($var->postName,$var->value); $go->AddComponent($pf_ser); } $anchor->AddComponent($go); $parrafo->AddNode($anchor); return $parrafo->toString(); }
function XML($url = '') { // Init external properties parent::XMLNode(); $this->status = 0; $this->error = ''; $this->version = '1.0'; $this->encoding = 'ISO-8859-1'; $this->contentType = 'text/xml'; $this->docTypeDecl = ''; $this->xmlDecl = ''; // Load the referenced XML document $this->load($url); }
/** * Add the metadata XML of a single article to an * XML article list. * * @param $articleDoc DOMDocument * @param $article PublishedArticle * @param $journal Journal * @param $markToDelete boolean If true the returned XML * will only contain a deletion marker. */ function _addArticleXml(&$articleDoc, &$article, &$journal, $markToDelete = false) { assert(is_a($article, 'Article')); // Get the root node of the list. assert(is_a($articleDoc, 'DOMDocument')); $articleList =& $articleDoc->documentElement; // Create a new article node. $articleNode =& XMLCustomWriter::createElement($articleDoc, 'article'); // Add ID information. XMLCustomWriter::setAttribute($articleNode, 'id', $article->getId()); XMLCustomWriter::setAttribute($articleNode, 'sectionId', $article->getSectionId()); XMLCustomWriter::setAttribute($articleNode, 'journalId', $article->getJournalId()); XMLCustomWriter::setAttribute($articleNode, 'instId', $this->_instId); // Set the load action. $loadAction = $markToDelete ? 'delete' : 'replace'; XMLCustomWriter::setAttribute($articleNode, 'loadAction', $loadAction); XMLCustomWriter::appendChild($articleList, $articleNode); // The XML for an article marked to be deleted contains no metadata. if ($markToDelete) { return; } assert(is_a($article, 'PublishedArticle')); // Add authors. $authors = $article->getAuthors(); if (!empty($authors)) { $authorList =& XMLCustomWriter::createElement($articleDoc, 'authorList'); foreach ($authors as $author) { /* @var $author Author */ XMLCustomWriter::createChildWithText($articleDoc, $authorList, 'author', $author->getFullName(true)); } XMLCustomWriter::appendChild($articleNode, $authorList); } // We need the request to retrieve locales and build URLs. $request = PKPApplication::getRequest(); // Get all supported locales. $site = $request->getSite(); $supportedLocales = $site->getSupportedLocales() + array_keys($journal->getSupportedLocaleNames()); assert(!empty($supportedLocales)); // Add titles. $titleList =& XMLCustomWriter::createElement($articleDoc, 'titleList'); // Titles are used for sorting, we therefore need // them in all supported locales. assert(!empty($supportedLocales)); foreach ($supportedLocales as $locale) { $localizedTitle = $article->getLocalizedTitle($locale); if (!is_null($localizedTitle)) { // Add the localized title. $titleNode =& XMLCustomWriter::createChildWithText($articleDoc, $titleList, 'title', $localizedTitle); XMLCustomWriter::setAttribute($titleNode, 'locale', $locale); // If the title does not exist in the given locale // then use the localized title for sorting only. $title = $article->getTitle($locale); $sortOnly = empty($title) ? 'true' : 'false'; XMLCustomWriter::setAttribute($titleNode, 'sortOnly', $sortOnly); } } XMLCustomWriter::appendChild($articleNode, $titleList); // Add abstracts. $abstracts = $article->getAbstract(null); // return all locales if (!empty($abstracts)) { $abstractList =& XMLCustomWriter::createElement($articleDoc, 'abstractList'); foreach ($abstracts as $locale => $abstract) { $abstractNode =& XMLCustomWriter::createChildWithText($articleDoc, $abstractList, 'abstract', $abstract); XMLCustomWriter::setAttribute($abstractNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $abstractList); } // Add discipline. $disciplines = $article->getDiscipline(null); // return all locales if (!empty($disciplines)) { $disciplineList =& XMLCustomWriter::createElement($articleDoc, 'disciplineList'); foreach ($disciplines as $locale => $discipline) { $disciplineNode =& XMLCustomWriter::createChildWithText($articleDoc, $disciplineList, 'discipline', $discipline); XMLCustomWriter::setAttribute($disciplineNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $disciplineList); } // Add subjects and subject classes. $subjectClasses = $article->getSubjectClass(null); $subjects = $article->getSubject(null); if (!empty($subjectClasses) || !empty($subjects)) { $subjectList =& XMLCustomWriter::createElement($articleDoc, 'subjectList'); if (!is_array($subjectClasses)) { $subjectClasses = array(); } if (!is_array($subjects)) { $subjects = array(); } $locales = array_unique(array_merge(array_keys($subjectClasses), array_keys($subjects))); foreach ($locales as $locale) { $subject = ''; if (isset($subjectClasses[$locale])) { $subject .= $subjectClasses[$locale]; } if (isset($subjects[$locale])) { if (!empty($subject)) { $subject .= ' '; } $subject .= $subjects[$locale]; } $subjectNode =& XMLCustomWriter::createChildWithText($articleDoc, $subjectList, 'subject', $subject); XMLCustomWriter::setAttribute($subjectNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $subjectList); } // Add type. $types = $article->getType(null); // return all locales if (!empty($types)) { $typeList =& XMLCustomWriter::createElement($articleDoc, 'typeList'); foreach ($types as $locale => $type) { $typeNode =& XMLCustomWriter::createChildWithText($articleDoc, $typeList, 'type', $type); XMLCustomWriter::setAttribute($typeNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $typeList); } // Add coverage. $coverageGeo = $article->getCoverageGeo(null); $coverageChron = $article->getCoverageChron(null); $coverageSample = $article->getCoverageSample(null); if (!empty($coverageGeo) || !empty($coverageChron) || !empty($coverageSample)) { $coverageList =& XMLCustomWriter::createElement($articleDoc, 'coverageList'); if (!is_array($coverageGeo)) { $coverageGeo = array(); } if (!is_array($coverageChron)) { $coverageChron = array(); } if (!is_array($coverageSample)) { $coverageSample = array(); } $locales = array_unique(array_merge(array_keys($coverageGeo), array_keys($coverageChron), array_keys($coverageSample))); foreach ($locales as $locale) { $coverage = ''; if (isset($coverageGeo[$locale])) { $coverage .= $coverageGeo[$locale]; } if (isset($coverageChron[$locale])) { if (!empty($coverage)) { $coverage .= '; '; } $coverage .= $coverageChron[$locale]; } if (isset($coverageSample[$locale])) { if (!empty($coverage)) { $coverage .= '; '; } $coverage .= $coverageSample[$locale]; } $coverageNode =& XMLCustomWriter::createChildWithText($articleDoc, $coverageList, 'coverage', $coverage); XMLCustomWriter::setAttribute($coverageNode, 'locale', $locale); } XMLCustomWriter::appendChild($articleNode, $coverageList); } // Add journal titles. $journalTitleList =& XMLCustomWriter::createElement($articleDoc, 'journalTitleList'); // Journal titles are used for sorting, we therefore need // them in all supported locales. foreach ($supportedLocales as $locale) { $localizedTitle = $journal->getName($locale); $sortOnly = false; if (is_null($localizedTitle)) { // If the title does not exist in the given locale // then use the localized title for sorting only. $journalTitle = $journal->getLocalizedName(); $sortOnly = true; } else { $journalTitle = $localizedTitle; } $journalTitleNode =& XMLCustomWriter::createChildWithText($articleDoc, $journalTitleList, 'journalTitle', $journalTitle); XMLCustomWriter::setAttribute($journalTitleNode, 'locale', $locale); $sortOnly = $sortOnly ? 'true' : 'false'; XMLCustomWriter::setAttribute($journalTitleNode, 'sortOnly', $sortOnly); } XMLCustomWriter::appendChild($articleNode, $journalTitleList); // Add publication dates. $publicationDate = $article->getDatePublished(); if (!empty($publicationDate)) { // Transform and store article publication date. $publicationDate = $this->_convertDate($publicationDate); $dateNode =& XMLCustomWriter::createChildWithText($articleDoc, $articleNode, 'publicationDate', $publicationDate); } $issueId = $article->getIssueId(); if (is_numeric($issueId)) { $issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */ $issue = $issueDao->getById($issueId); if (is_a($issue, 'Issue')) { $issuePublicationDate = $issue->getDatePublished(); if (!empty($issuePublicationDate)) { // Transform and store issue publication date. $issuePublicationDate = $this->_convertDate($issuePublicationDate); $dateNode =& XMLCustomWriter::createChildWithText($articleDoc, $articleNode, 'issuePublicationDate', $issuePublicationDate); } } } // We need the router to build file URLs. $router = $request->getRouter(); /* @var $router PageRouter */ // Add galley files $articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO'); $galleys = $articleGalleyDao->getBySubmissionId($article->getId()); $galleyList = null; while ($galley = $galleys->next()) { /* @var $galley ArticleGalley */ $locale = $galley->getLocale(); $galleyUrl = $router->url($request, $journal->getPath(), 'article', 'download', array(intval($article->getId()), intval($galley->getId()))); if (!empty($locale) && !empty($galleyUrl)) { if (is_null($galleyList)) { $galleyList =& XMLCustomWriter::createElement($articleDoc, 'galleyList'); } $galleyNode =& XMLCustomWriter::createElement($articleDoc, 'galley'); XMLCustomWriter::setAttribute($galleyNode, 'locale', $locale); XMLCustomWriter::setAttribute($galleyNode, 'fileName', $galleyUrl); XMLCustomWriter::appendChild($galleyList, $galleyNode); } } // Wrap the galley XML as CDATA. if (!is_null($galleyList)) { if (is_callable(array($articleDoc, 'saveXml'))) { $galleyXml = $articleDoc->saveXml($galleyList); } else { $galleyXml = $galleyList->toXml(); } $galleyOuterNode =& XMLCustomWriter::createElement($articleDoc, 'galley-xml'); if (is_callable(array($articleDoc, 'createCDATASection'))) { $cdataNode = $articleDoc->createCDATASection($galleyXml); } else { $cdataNode = new XMLNode(); $cdataNode->setValue('<![CDATA[' . $galleyXml . ']]>'); } XMLCustomWriter::appendChild($galleyOuterNode, $cdataNode); XMLCustomWriter::appendChild($articleNode, $galleyOuterNode); } }
function parseXML($source) { // Clear any content that this object might have // Call: $this->removeNode() // Get xml declration from document and set in object if (preg_match("/<?xml\\ (.*?)\\?>/i", $source, $matches)) { $this->xmlDecl = "<?xml " . $matches[1] . "?>"; // Get version if (preg_match("/version=\"(.*?)\"/i", $matches[1], $versionInfo)) { $this->version = $versionInfo[1]; } // Get encoding if (preg_match("/encoding=\"(.*?)\"/i", $matches[1], $encodingInfo)) { $this->encoding = $encodingInfo[1]; } } // Get document type decleration from document and set in object if (preg_match("/<!doctype\\ (.*?)>/i", $source, $matches)) { $this->docTypeDecl = "<!DOCTYPE " . $matches[1] . ">"; } // Strip white space between tags - not _in_ tags $source = preg_replace("/>\\s+</i", "><", $source); $source = preg_replace("/[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]/", '', $source); // Parse the xml document to an array structure //$parser = xml_parser_create($this->encoding); $parser = xml_parser_create('ISO-8859-1'); //$parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); $ret = xml_parse_into_struct($parser, $source, $vals); xml_parser_free($parser); // parse the structure and create this object... if (!empty($vals)) { $root = XMLNode::createElement($vals[0]['tag']); $root->attributes = isset($vals[0]['attributes']) ? $vals[0]['attributes'] : NULL; $root->childNodes = $root->_xml_get_children($vals, $i = 0); $this->appendChild($root); } return $ret; }
public function Button($value) { parent::XMLNode("input", ""); $this->createAttribute("value", $value); }
function setContent($new_content) { $data = new XMLNode("data", array("id" => "data")); for ($i = 0; $i < count($new_content); $i++) { $data->addChild($new_content[$i]); } $this->content->xml->addChild($data); }
public function addArray($value) { foreach ($value as $k => $v) { if (is_int($k)) { $k = "item"; } if (is_array($v)) { $node = new XMLNode($k); $node->addArray($v); $this->addValue(null, $node); } else { $this->addValue($k, $v); } } }
/** * Creates a child node of the current element. * $content is optional. * * @access public * @param string $name * @param string $content * @return resource * */ function &addChild($name, $content = '') { // returns XMLNode object, stores internal pointer $count = 0; foreach ($this->children as $child) { if ($name == $child->name) { $count++; } } $obj = new XMLNode($name, $content, $count, $this); if ($this->propagateCallback) { if ($this->callbackEnd) { $obj->setCallback($this->callbackStart, $this->callbackEnd, $this->callbackObject); } else { $obj->setCallback($this->callbackStart, $this->callbackObject); } $obj->propagateCallback = true; } $this->children[] = $obj; if (!isset($this->{'_' . $obj->name})) { $this->{'_' . $obj->name} =& $this->children[count($this->children) - 1]; } elseif (!is_array($this->{'_' . $obj->name})) { $tmp =& $this->{'_' . $obj->name}; unset($this->{'_' . $obj->name}); $this->{'_' . $obj->name} = array(); $this->{'_' . $obj->name}[] =& $tmp; $this->{'_' . $obj->name}[] =& $this->children[count($this->children) - 1]; } else { $this->{'_' . $obj->name}[] =& $this->children[count($this->children) - 1]; } return $this->children[count($this->children) - 1]; }