eZXMLInputParser::process PHP Method

process() public method

*! \public Call this function to process your input
public process ( $text, $createRootNode = true )
    function process($text, $createRootNode = true)
    {
        $text = str_replace("\r", '', $text);
        $text = str_replace("\t", ' ', $text);
        // replace unicode chars that will break the XML validity
        // see http://www.w3.org/TR/REC-xml/#charsets
        $text = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $text, -1, $count);
        if ($count > 0) {
            $this->Messages[] = ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "%count invalid character(s) have been found and replaced by a space", false, array('%count' => $count));
        }
        if (!$this->ParseLineBreaks) {
            $text = str_replace("\n", '', $text);
        }
        $this->Document = new $this->DOMDocumentClass('1.0', 'utf-8');
        if ($createRootNode) {
            $this->createRootNode();
        }
        // Perform pass 1
        // Parsing the source string
        $this->performPass1($text);
        //$this->Document->formatOutput = true;
        $debug = eZDebugSetting::isConditionTrue('kernel-datatype-ezxmltext', eZDebug::LEVEL_DEBUG);
        if ($debug) {
            eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'XML after pass 1'));
        }
        if ($this->QuitProcess) {
            return false;
        }
        // Perform pass 2
        $this->performPass2();
        //$this->Document->formatOutput = true;
        if ($debug) {
            eZDebug::writeDebug($this->Document->saveXML(), eZDebugSetting::changeLabel('kernel-datatype-ezxmltext', 'XML after pass 2'));
        }
        if ($this->QuitProcess) {
            return false;
        }
        return $this->Document;
    }

Usage Example

Esempio n. 1
0
 /**
  * Process html text and transform it to xml.
  *
  * @param string $text
  * @param bool $createRootNode
  * @return false|DOMDocument
  */
 public function process($text, $createRootNode = true)
 {
     $text = preg_replace('#<!--.*?-->#s', '', $text);
     // remove HTML comments
     $text = str_replace(array('&nbsp;', '&#160;', '&#xa0;'), " ", $text);
     return parent::process($text, $createRootNode);
 }
All Usage Examples Of eZXMLInputParser::process