function handle($match, $state, $pos, Doku_Handler $handler) { switch ($state) { case DOKU_LEXER_SPECIAL: $matches = preg_split('/(&&XML&&\\n*|\\n*&&XSLT&&\\n*|\\n*&&END&&)/', $match, 5); $data = "XML: " . $matches[1] . "\nXSLT: " . $matches[2] . "(" . $match . ")"; $xsltproc = new XsltProcessor(); $xml = new DomDocument(); $xsl = new DomDocument(); $xml->loadXML($matches[1]); $xsl->loadXML($matches[2]); $xsltproc->registerPHPFunctions(); $xsltproc->importStyleSheet($xsl); $data = $xsltproc->transformToXML($xml); if (!$data) { $errors = libxml_get_errors(); foreach ($errors as $error) { $data = display_xml_error($error, $xml); } libxml_clear_errors(); } unset($xsltproc); return array($state, $data); case DOKU_LEXER_UNMATCHED: return array($state, $match); case DOKU_LEXER_EXIT: return array($state, ''); } return array(); }
public function getXmlResult() { libxml_use_internal_errors(true); $xmlResult = new \SimpleXMLElement(trim($this->getRawResult())); //error handling if (!$xmlResult) { $errArr = array(); $errors = libxml_get_errors(); foreach ($errors as $error) { $errArr[] = display_xml_error($error, $xml); } libxml_clear_errors(); throw new \Exception(implode(', ', $errArr)); } //error handling if (isset($xmlResult->diagnosis->severity) && $xmlResult->diagnosis->severity == 'error') { throw new \Exception($xmlResult->diagnosis->message); } return $xmlResult; }
function test_xml($f) { $d = get_file($f); echo $enc = embed_detect(strtolower($d), 'encoding="', '"'); if (strtolower($enc) == 'utf-8') { $d = utf8_decode_b($d); } //echo substr_count($d,'<').'-'.substr_count($d,'>'); eco($d, 1); $r = simplexml_load_string($d); $xml = explode("\n", $f); if (!$r) { $rr = libxml_get_errors(); foreach ($rr as $er) { $ret .= display_xml_error($er, $xml); } libxml_clear_errors(); return $ret; } }
public function getContent($section) { if (isset($this->urls[$section])) { $contents = $this->getURL($this->urls[$section]); libxml_use_internal_errors(true); $doc = simplexml_load_string($contents); if (!$doc) { $errors = libxml_get_errors(); $html = ''; foreach ($errors as $error) { $html .= nl2br(display_xml_error($error, $contents)) . "<br/>"; } libxml_clear_errors(); return $html; } $items = array(); $limit = 5; $c = 0; return load_view(dirname(__DIR__) . '/views/sections/blog.php', array("items" => $doc->channel->item, "limit" => 5)); } }
print "Usage: {$argv['0']} filename.xml\n"; exit(1); } $file = $argv[1]; if (!file_exists($file)) { print "Usage: can't read {$file}\n"; exit(1); } $xmlstr = file_get_contents($file); libxml_use_internal_errors(true); $doc = @simplexml_load_string($xmlstr, 'SimpleXMLElement', LIBXML_NOCDATA); $xml = explode("\n", $xmlstr); if (!$doc) { $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error, $xml); } libxml_clear_errors(); exit(1); } else { print "XML loaded successfully\n"; exit(0); } function display_xml_error($error, $xml) { $return = $xml[$error->line - 1] . "\n"; $return .= str_repeat('-', $error->column) . "^\n"; switch ($error->level) { case LIBXML_ERR_WARNING: $return .= "Warning {$error->code}: "; break;
} } } } } else { $error = 2; $errmsg = getTranslatedString('err_invalidupdatefile', $currentModule) . '<br>'; foreach (libxml_get_errors() as $err) { $errmsg .= display_xml_error($err); } libxml_clear_errors(); } } else { $error = 3; $errmsg = getTranslatedString('err_invalidupdatefile', $currentModule) . '<br>'; foreach (libxml_get_errors() as $err) { $errmsg .= display_xml_error($err); } libxml_clear_errors(); } } //foreach } else { $error = 4; $errmsg = getTranslatedString('err_noupdatefile', $currentModule); } if ($error) { echo $error; } else { echo trim($cbupdate_ids, ','); }
$strLine = ''; logError(0, $strDescription, $strLine, 2); } else { $bDebugLogFileOpen = true; // Log open log-filename $strDescription = '- open debug log filename [' . $filepathDebugLog . ']' . PHP_EOL; $strLine = ''; logLog(0, $strDescription, $strLine, 2); } } // Log-file open // write xml validate error to debug log if ($bDebugLogFileOpen) { $errors = libxml_get_errors(); foreach ($errors as $error) { fwrite($fDebugLog, display_xml_error($error)); } libxml_clear_errors(); } } // END if (0 < $nXmlValidateError ) ## END validate errors? ## ## Close section well-formed & validate ## if ($bDebugLogFileOpen) { fclose($fDebugLog); $bDebugLogFileOpen = false; } ## Close section well-formed & validate ## } // END IF (true) ### XML Reader section ###
function check_xml_is_valid($xml_input) { // Check that they are valid libxml_use_internal_errors(true); $ret = simplexml_load_string($xml_input); if ($ret == FALSE) { $errors = libxml_get_errors(); $xml = explode("\n", $xml_input); $msg = ""; foreach ($errors as $error) { $msg .= htmlspecialchars(display_xml_error($error, $xml)) . "<br />"; } libxml_clear_errors(); return $msg; } return ''; }
function display_xml_errors() { global $texto; $lineas = explode("\n", $texto); $errors = libxml_get_errors(); echo "<pre>"; foreach ($errors as $error) { echo display_xml_error($error, $lineas); } echo "</pre>"; libxml_clear_errors(); }
function parseRequestRSpecContents($rspec) { $am_urns = array(); $is_bound = false; $has_unbound_node = false; $is_stitch = false; $dom_document = new DOMDocument(); $ret = $dom_document->loadXML($rspec); if (!$ret) { error_log("Failed to parse request RSpec"); $errors = libxml_get_errors(); $xmlstr = explode("\n", $rspec); foreach ($errors as $error) { $errstr = display_xml_error($error, $xmlstr); error_log($errstr); } libxml_clear_errors(); return NULL; } $root = $dom_document->documentElement; // Go over each node and link child // If ANY node child has a component_manager_id, is_bound is true // If ANY link has two componennt_manager children of // different names, is_stitch is true foreach ($root->childNodes as $child) { if ($child->nodeType == XML_TEXT_NODE) { continue; } // Pull out 'client_id' and 'component_manager_id' attributes if ($child->nodeName == 'node') { $node = $child; $client_id = NULL; if ($node->hasAttribute('client_id')) { $client_id = $node->getAttribute('client_id'); } $component_manager_id = NULL; if ($node->hasAttribute('component_manager_id')) { $component_manager_id = $node->getAttribute('component_manager_id'); $is_bound = true; if (!in_array($component_manager_id, $am_urns)) { $am_urns[] = $component_manager_id; } } else { $has_unbound_node = true; } // error_log("Node " . print_r($node, true) . " " . // print_r($client_id, true) . " " . // print_r($component_manager_id, true)); } elseif ($child->nodeName == 'link') { $link_urns = array(); // Extract the client_id attribute and // component_manager_id child name attribute $link = $child; $link_client_id = NULL; if ($link->hasAttribute('client_id')) { $link_client_id = $link->getAttribute('client_id'); } // error_log("Link " . print_r($link, true) . " " . // print_r($link_client_id, true)); foreach ($link->childNodes as $link_child) { if ($link_child->nodeType == XML_TEXT_NODE) { continue; } if ($link_child->nodeName == 'component_manager') { $cm_id = $link_child; $cmid_component_manager_id = NULL; if ($cm_id->hasAttribute('name')) { $cmid_component_manager_id = $cm_id->getAttribute('name'); $link_urns[$cmid_component_manager_id] = true; } // error_log(" CMID:" . print_r($cm_id, true) . " " . // print_r($cmid_component_manager_id, true)); } } // We have a link with more than 1 different aggregate URN if (count(array_keys($link_urns)) > 1) { $is_stitch = true; } } } $is_partially_bound = ($is_bound and $has_unbound_node); return array($rspec, $is_bound, $is_stitch, $am_urns, $is_partially_bound); }
if ($ext == '.xml') { $xml = file_get_contents($_FILES['upload']['tmp_name']); unlink($_FILES['upload']['tmp_name']); $xml = utf8_encode($xml); $test = mb_substr($xml,0,mb_strpos($xml,'>')+1); if ( $test == '<commsy_export>') { $do_it = true; } } if ($do_it) { libxml_use_internal_errors(true); $xml_object = simplexml_load_string($xml,'cNode'); if (!$xml_object) { $errors = libxml_get_errors(); foreach ($errors as $error) { echo(display_xml_error($error,$xml)); } libxml_clear_errors(); exit(); } $commsy_version = utf8_decode((string)$xml_object->version); $current_commsy_version = getCommSyVersion(); if ( $current_commsy_version != $commsy_version ) { $params = array(); $params['environment'] = $environment; $params['with_modifying_actions'] = true; $params['width'] = 500; $errorbox = $class_factory->getClass(ERRORBOX_VIEW,$params); unset($params);
/** * Hooks into the {@the_content} of each posts and breaks the text into an array. * * * @since 3.0.0 * * @param string $html Required. Comment amount in post if > 0, else total comments blog wide. * @param string $tags Optional * @return array An array of each text block with the proper html tags for comment count and extra tags for adding javascript hooks */ function standard_digressit_content_parser($html, $tags = 'div|table|object|p|ul|ol|blockquote|code|h1|h2|h3|h4|h5|h6|h7|h8', $return_paragraphs = false) { global $post; $matches = array(); $html = strip_selected_tags($html, '<hr>'); //we need to do this twice in case there are empty tags surrounded by empty p tags $html = preg_replace('/<(?!input|br|iframe|object|param|embed|img|meta|hr|\\/)[^>]*>\\s*<\\/[^>]*>/ ', '', $html); $html = preg_replace('/<(?!input|br|iframe|object|param|embed|img|meta|hr|\\/)[^>]*>\\s*<\\/[^>]*>/ ', '', $html); $html = str_replace("</iframe>", " </iframe>", $html); $digressit_options = get_option('digressit'); $blocks = array(); $text_signatures = null; $permalink = get_permalink($post->ID); $defaults = array('post_id' => $post->ID); $total_comments = get_comments($defaults); $total_count = count($total_comments); if ($digressit_options['parse_list_items'] == 1) { $html = preg_replace('/<(\\/?ul|ol)>/', '', $html); $html = preg_replace('/<li>/', '<p>* ', $html); } $html = wpautop(force_balance_tags($html)); $html = str_replace(' ', '', $html); $html = str_replace('©', '(c)', $html); // $html = preg_replace("/&#?[a-z0-9]{2,8};/i","",$html); libxml_use_internal_errors(true); if ($result = @simplexml_load_string(trim('<content>' . $html . '</content>'))) { $xml = $result->xpath('/content/' . $tags); foreach ($xml as $match) { $matches[] = $match->asXML(); } } else { if (current_user_can('edit_posts')) { $matches[] = "There was a problem parsing your content. Please make sure that every HTML tag is properly nested and closed. \n To validate your text, and to try and repair it, use the <a href='https://wordpress.org/extend/plugins/tidy-up/'>Tidy Up</a> plugin for WordPress."; if (!$result) { $errors = libxml_get_errors(); foreach ($errors as $error) { $error_messages .= display_xml_error($error, $xml) . "<br>"; } libxml_clear_errors(); } $matches[] = $error_messages; } else { $matches[] = "Sorry! There was a problem loading the contents of this post. Please notify the site administrator."; } } if ($return_paragraphs) { return $matches; } foreach ($matches as $key => $paragraph) { $text_signature = $key + 1; $text_signatures[] = $text_signature; $paranumber = $number = $key + 1; $comment_count = 0; foreach ($total_comments as $c) { if ($c->comment_text_signature == $paranumber) { $comment_count++; } } $paragraphnumber = '<span class="paragraphnumber">'; $numbertext = $comment_count == 1 ? 'is one comment' : 'are ' . $comment_count . ' comments'; $numbertext = $comment_count == 0 ? 'are no comments' : $numbertext; $digit_count = strlen($comment_count); $commenticon = '<span title="There ' . $numbertext . ' for this paragraph" class="commenticonbox"><small class="commentcount fff commentcount' . $digit_count . '">' . $comment_count . '</small></span>' . "\n"; $morelink = null; if ($number == 1) { //$morelink = '<span class="morelink"></span>'; } else { $morelink = null; } $matches = null; preg_match_all('/class=\\"([^"]+)\\"/is', $paragraph, $matches); if (count($matches)) { foreach ($matches[1] as $match) { if (strstr($match, 'wp-image')) { $paragraph = str_replace($match, 'lightbox lightbox-images ' . $match, $paragraph); } $paragraph = str_replace(" class=\"{$matches}\" ", " class=\"lightbox lightbox-images {$classes}\" ", $paragraph); } } $block_content = "<div id='textblock-{$number}' class='textblock'>\n <span class='paragraphnumber'><a href='{$permalink}#{$number}'>{$number}</a></span>"; if ($digressit_options['enable_citation_button'] == 1) { $block_content .= "<span class='paragraphembed'>\n <a href='#' rel='{$number}'>“</a>\n <span class='embedcode' id='embedcode-{$number}'>\n <a href='#' class='closeme'>x</a>\n <b>Cite</b> <input type='text' value='" . $post->guid . "&digressit-embed={$number}&format=html'><br>\n <b>Embed</b><br>\n <textarea><blockquote cite='{$permalink}#{$number}'>" . force_balance_tags($paragraph) . "</blockquote></textarea>\n <span class='text-copied'>Text copied</span>\n </span>\n </span>"; } $block_content .= "<span title='There {$numbertext} for this paragraph' class='commenticonbox'><small class='commentcount commentcount" . $digit_count . "'>" . $comment_count . "</small></span>\n <span class='paragraphtext'>" . force_balance_tags($paragraph) . "</span>\n </div>" . $morelink; $blocks[$paranumber] = $block_content; } global $post_paragraph_count; $post_paragraph_count = count($blocks); return $blocks; }
$validate = $dom->schemaValidate($schema) ? "<p class='center grand vert'>Le schéma XML paraît valide !</p>" : "<p class='center grand rouge'>Schéma XML non valide !</p>"; * */ if (!$dom->schemaValidate($schema)) { ?> <p class='center grand rouge'>Validation du schema d'export → Votre fichier <?php echo $nomFichier; ?> n'est pas valide</p> <?php //libxml_display_errors(); $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error); } } unset($dom); // Affichage du résultat //echo $validate; if (isset($messages)) { ?> <p class="center grand bold rouge" onclick="bascule('messages')" style="cursor:pointer" title="Cliquez pour déplier/plier"> <?php echo count($messages); ?> appréciation<?php
function sb_load_xml($xml_file) { global $sb_config; echo "\n<!-- xml file: {$xml_file} -->\n"; $data = FALSE; $error = ''; $error_msg = ''; if (ini_get('allow_url_fopen')) { echo "<!-- SmartBroker: Loading XML via file_get_contents-->\n"; $data = @file_get_contents($xml_file); if ($data === FALSE) { echo "<!-- SmartBroker: Loading XML via file_get_contents fail -->\n"; $error .= "file_get_contents failure for '{$xml_file}'.\r\n"; } else { echo "<!-- SmartBroker: Loading XML via file_get_contents success: " . strlen($data) . " bytes loaded-->\n"; } } if ($data === FALSE and function_exists("curl_exec")) { echo "\n<!-- SmartBroker: Loading XML via cURL-->\n"; $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $xml_file); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($ch); curl_close($ch); if ($data === FALSE) { echo "<!-- SmartBroker: Loading XML via cURL fail -->\n"; $error .= "cURL failure for '{$xml_file}'.\r\n"; } else { echo "<!-- SmartBroker: Loading XML via cURL success: " . strlen($data) . " bytes loaded-->\n"; } } elseif ($data === FALSE) { echo "<!-- SmartBroker: No way of loading data! -->\n"; $error .= "No cURL option available either, exiting.\r\n"; } libxml_use_internal_errors(true); $sxe = @simplexml_load_string($data); if ($sxe === FALSE) { $error .= "simple_xml_load_string error for data from for '{$xml_file}'. Errors follow:\r\n"; foreach (libxml_get_errors() as $e) { $error .= display_xml_error($e, $xml); } if ($data == 'Error: ID not valid') { $error_msg = "<h3>Well, this is embarrassing...</h3>\r\n\t\t\t<p>I'm afraid we can't find the listing you're looking for. Maybe <a href='?page_id=" . $sb_config['search_page'] . "' >search again</a>?</p>"; } } else { echo "<!-- SmartBroker: Data conversion to XML success -->\r\n"; return $sxe; } //if we get here we've got errors wp_mail('*****@*****.**', 'XML load error', "<pre>\r\n" . $error . "\n\nRequest URI: http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "\r\n</pre>"); if ($error_msg != '') { echo $error_msg; } else { echo "<h3>Well, this is embarrassing...</h3>\r\n\t\t<p>It appears that we're having a small technical problem at the moment. This issue has been reported to our support staff, so please check back here soon.</p>"; } return FALSE; }
$stmt->bindValue(':link_endereco', trim($objXml->endereco), \PDO::PARAM_STR); } else { $stmt->bindValue(':link_endereco', null, \PDO::PARAM_NULL); } if (property_exists($objXml, 'contato')) { $stmt->bindValue(':link_contato', trim($objXml->contato), \PDO::PARAM_STR); } else { $stmt->bindValue(':link_contato', null, \PDO::PARAM_NULL); } $stmt->bindValue(':tx_versao_consulta', trim($objXml->versaoConsulta), \PDO::PARAM_STR); $stmt->execute(); } else { $tmp = "ERRO: Não foi possível converter a linha {$l} em um objeto:\n"; $errors = libxml_get_errors(); foreach ($errors as $error) { $log->addLog($tmp . display_xml_error($error, $linha)); } libxml_clear_errors(); } $strXml = ''; } //FIM WHILE $log->addLog('Fim da leitura dos dados'); $cnnBanco->commit(); } fclose($hdlDados); $log->generateLog(); } catch (Exception $e) { try { $cnnBanco->rollBack(); } catch (Exception $e1) {
protected function process_transform($form, $endpoint, $transform, $message, $as_string) { if (is_string($message)) { $document = new DOMDocument(); $document->loadXML($message); } else { if ($message instanceof DOMDocument) { $document = $message; } else { if ($message instanceof DOMNode) { $document = $message->ownerDocument; } else { I2CE::raiseError("Invalid object sent to transformer"); return false; } } } if (!$document instanceof DOMDocument) { I2CE::RaiseError("Could not load message as XML Doc"); return false; } if (array_key_exists($endpoint, $this->services[$form]) && is_array($this->services[$form][$endpoint]) && array_key_exists('transforms', $this->services[$form][$endpoint]) && is_array($this->services[$form][$endpoint]['transforms'])) { $transforms = $this->services[$form][$endpoint]['transforms']; } else { $transforms = array(); } $error_on_src_file = true; if (array_key_exists($transform, $transforms) && is_string($transforms[$transform])) { $transform_src = $transforms[$transform]; } else { $transform_src = '@' . $form . DIRECTORY_SEPARATOR . $endpoint . '_' . $transform . '.xsl'; $error_on_src_file = false; } if ($transform_src == '0') { //no outgoing message return ''; } if ($transform_src[0] == '@') { //it's a file. search for it. $file = substr($transform_src, 1); if (!($transform_file = I2CE::getFileSearch()->search('XSLTS', $file)) || !($transform_src = file_get_contents($transform_file))) { if ($error_on_src_file) { I2CE::raiseError("Invalid transform file at {$file} => {$transform_file}\n" . print_r(I2CE::getFileSearch()->getSearchPath('XSLTS'), true)); return false; } else { $transform_src = false; } } } if (!$transform_src) { if ($as_string) { return $document->saveXML(); } else { return $document; } } //try to do the transofmr $proc = new XSLTProcessor(); $xslDoc = new DOMDocument(); if (!$xslDoc->loadXML($transform_src)) { I2CE::raiseError("Invalid XSLT document form {$form}/{$endpoint}/{$transform}"); $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error, $xml); } return false; } if (!@$proc->importStylesheet($xslDoc)) { I2CE::raiseError("Could not import style sheet"); return false; } if (($out = @$proc->transformToXML($document)) === false) { I2CE::raiseError("Could not transform accoring to xsl"); return false; } I2CE::raiseError("Transformed to:\n{$out}"); if ($as_string) { return $out; } else { $out_doc = new DOMDocument(); if (!$out || !$out_doc->loadXML($out)) { return false; } return $out_doc; } }