本文整理汇总了PHP中XML_Util::collapseEmptyTags方法的典型用法代码示例。如果您正苦于以下问题:PHP XML_Util::collapseEmptyTags方法的具体用法?PHP XML_Util::collapseEmptyTags怎么用?PHP XML_Util::collapseEmptyTags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XML_Util
的用法示例。
在下文中一共展示了XML_Util::collapseEmptyTags方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Transforms a given XML string using the registered
* PHP callbacks for overloaded tags.
*
* @param string
* @return string
* @access public
*/
function transform($xml)
{
// Do not process input when it contains no XML elements.
if (strpos($xml, '<') === FALSE) {
return $xml;
}
// Replace all occurrences of the '&' character that are not directly
// followed by 'amp;' with the '&' entity.
$xml = preg_replace('/&(?!amp;)/i', '&', $xml);
// Create XML parser, set parser options.
$parser = xml_parser_create();
xml_set_object($parser, $this);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, $this->_caseFolding);
// Register SAX callbacks.
xml_set_element_handler($parser, '_startElement', '_endElement');
xml_set_character_data_handler($parser, '_characterData');
xml_set_default_handler($parser, '_characterData');
// Parse input.
if (!xml_parse($parser, $xml, TRUE)) {
$line = xml_get_current_line_number($parser);
$errorMessage = sprintf("Transformer: XML Error: %s at line %d:%d\n", xml_error_string(xml_get_error_code($parser)), $line, xml_get_current_column_number($parser));
$exml = preg_split('/\\n/', $xml);
$start = $line - 3 > 0 ? $line - 3 : 0;
$end = $line + 3 < sizeof($exml) ? $line + 3 : sizeof($exml);
for ($i = $start; $i < $end; $i++) {
$errorMessage .= sprintf("line %d: %s\n", $i + 1, $exml[$i]);
}
$this->sendMessage($errorMessage . "\n" . $this->stackdump(), $this->_logTarget);
return '';
}
$result = $this->_cdataStack[0];
// Clean up.
xml_parser_free($parser);
$this->_attributesStack = array();
$this->_cdataStack = array('');
$this->_elementStack = array();
$this->_level = 0;
$this->_lastProcessed = '';
// Perform second transformation pass, if required.
$secondPassRequired = $this->_secondPassRequired;
if ($secondPassRequired) {
$this->_depth++;
$this->_secondPassRequired = FALSE;
$result = $this->transform($result);
$this->_depth--;
}
if ($this->_collapseEmptyTags && $this->_depth == 0) {
$result = XML_Util::collapseEmptyTags($result, $this->_collapseEmptyTagsMode);
}
$this->_secondPassRequired = $secondPassRequired;
// Return result of the transformation.
return $result;
}