本文整理汇总了PHP中xml_set_default_handler函数的典型用法代码示例。如果您正苦于以下问题:PHP xml_set_default_handler函数的具体用法?PHP xml_set_default_handler怎么用?PHP xml_set_default_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml_set_default_handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open
function open($xml, $encoding = null)
{
if (!empty($encoding) && strtolower($encoding) != 'utf-8' && !Utils_Unicode::validate($xml)) {
if (preg_match('/^<\\?xml[^<]*\\s+encoding=["\']?([\\w-]+)["\']?/', $xml, $matches)) {
$encoding = $matches[1];
$xml = preg_replace('/^(<\\?xml[^<]*\\s+encoding=)["\']?[\\w-]+["\']?/', '$1"utf-8"', $xml, 1);
}
if (strcasecmp($encoding, 'utf-8')) {
$xml = Utils_Unicode::bring($xml, $encoding);
if (is_null($xml)) {
$this->error = XML_ERROR_UNKNOWN_ENCODING;
return false;
}
}
} else {
if (substr($xml, 0, 3) == "") {
$xml = substr($xml, 3);
}
}
$p = xml_parser_create();
xml_set_object($p, $this);
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($p, 'o', 'c');
xml_set_character_data_handler($p, 'd');
xml_set_default_handler($p, 'x');
$this->tree = array('children' => array());
$this->_cursor =& $this->tree;
$this->_cdata = false;
xml_parse($p, $xml);
unset($this->_cursor);
unset($this->_cdata);
$this->error = xml_get_error_code($p);
xml_parser_free($p);
return $this->error == XML_ERROR_NONE;
}
示例2: parse
public function parse($html)
{
// replace entities
$html = preg_replace('/&([a-z0-9#]{2,5});/i', '+$1;', $html);
//before sending to xml parser make sure we have valid xml by tidying it up
$html = Kwf_Util_Tidy::repairHtml($html);
$this->_stack = array();
$this->_ret = '';
$this->_parser = xml_parser_create();
xml_set_object($this->_parser, $this);
xml_set_element_handler($this->_parser, 'startElement', 'endElement');
xml_set_character_data_handler($this->_parser, 'characterData');
xml_set_default_handler($this->_parser, 'characterData');
$result = xml_parse($this->_parser, '<body>' . $html . '</body>', true);
if (!$result) {
// wenn man ein nicht geschlossenes <br> rein gibt, schreit er hier,
// macht aber normal weiter. wenns zu oft vorkommt, evtl. exception
// entfernen und ignorieren, oder was andres überlegen :-)
$errorCode = xml_get_error_code($this->_parser);
$ex = new Kwf_Exception("HtmlExport UrlParser XML Error {$errorCode}: " . xml_error_string($errorCode) . "in line " . xml_get_current_line_number($this->_parser) . " parsed html: " . $html);
$ex->logOrThrow();
}
// re-replace entities
$this->_ret = preg_replace('/\\+([a-z0-9#]{2,5});/i', '&$1;', $this->_ret);
return $this->_ret;
}
示例3: parse
function parse()
{
set_error_handler(array(&$this, 'error_handler'));
array_unshift($this->ns_contexts, array());
$parser = xml_parser_create_ns();
xml_set_object($parser, $this);
xml_set_element_handler($parser, "start_element", "end_element");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
xml_set_character_data_handler($parser, "cdata");
xml_set_default_handler($parser, "_default");
xml_set_start_namespace_decl_handler($parser, "start_ns");
xml_set_end_namespace_decl_handler($parser, "end_ns");
$this->content = '';
$ret = true;
$fp = fopen($this->FILE, "r");
while ($data = fread($fp, 4096)) {
if ($this->debug) {
$this->content .= $data;
}
if (!xml_parse($parser, $data, feof($fp))) {
trigger_error(sprintf(__('XML error: %s at line %d') . "\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
$ret = false;
break;
}
}
fclose($fp);
xml_parser_free($parser);
restore_error_handler();
return $ret;
}
示例4: __construct
public function __construct($input, $maxDepth = 20)
{
if (!is_string($input)) {
throw new XmlToArrayException('No valid input.');
}
$this->_maxDepth = $maxDepth;
$XMLParser = xml_parser_create();
xml_parser_set_option($XMLParser, XML_OPTION_SKIP_WHITE, false);
xml_parser_set_option($XMLParser, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($XMLParser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_character_data_handler($XMLParser, array($this, '_contents'));
xml_set_default_handler($XMLParser, array($this, '_default'));
xml_set_element_handler($XMLParser, array($this, '_start'), array($this, '_end'));
xml_set_external_entity_ref_handler($XMLParser, array($this, '_externalEntity'));
xml_set_notation_decl_handler($XMLParser, array($this, '_notationDecl'));
xml_set_processing_instruction_handler($XMLParser, array($this, '_processingInstruction'));
xml_set_unparsed_entity_decl_handler($XMLParser, array($this, '_unparsedEntityDecl'));
if (!xml_parse($XMLParser, $input, true)) {
$errorCode = xml_get_error_code($XMLParser);
$message = sprintf('%s. line: %d, char: %d' . ($this->_tagStack ? ', tag: %s' : ''), xml_error_string($errorCode), xml_get_current_line_number($XMLParser), xml_get_current_column_number($XMLParser) + 1, implode('->', $this->_tagStack));
xml_parser_free($XMLParser);
throw new XmlToArrayException($message, $errorCode);
}
xml_parser_free($XMLParser);
}
示例5: XMLParser
function XMLParser()
{
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, FALSE);
xml_set_element_handler($this->parser, "startElementhandler", "endElementHandler");
xml_set_character_data_handler($this->parser, "cdataHandler");
xml_set_processing_instruction_handler($this->parser, "processingInstructionHandler");
xml_set_default_handler($this->parser, "defaultHandler");
}
示例6: txpXmlParser
function txpXmlParser()
{
$this->xml = xml_parser_create('UTF-8');
xml_parser_set_option($this->xml, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($this->xml, $this);
xml_set_character_data_handler($this->xml, 'dataHandler');
xml_set_element_handler($this->xml, "startHandler", "endHandler");
xml_set_default_handler($this->xml, 'defaultHandler');
}
示例7: createParser
function createParser($filename)
{
$fh = fopen($filename, 'r');
$parser = xml_parser_create();
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
xml_set_processing_instruction_handler($parser, "processingInstruction");
xml_set_default_handler($parser, "default");
return array($parser, $fh);
}
示例8: soap_parser
function soap_parser($xml = '', $encoding = 'UTF-8')
{
global $soapTypes;
$this->soapTypes = $soapTypes;
$this->xml = $xml;
$this->xml_encoding = $encoding;
$this->root_struct = "";
// options: envelope,header,body,method
// determines where in the message we are (envelope,header,body,method)
$this->status = '';
$this->position = 0;
$this->pos_stat = 0;
$this->depth = 0;
$this->default_namespace = '';
$this->namespaces = array();
$this->message = array();
$this->fault = false;
$this->fault_code = '';
$this->fault_str = '';
$this->fault_detail = '';
$this->eval_str = '';
$this->depth_array = array();
$this->debug_flag = True;
$this->debug_str = '';
$this->previous_element = '';
$this->entities = array('&' => '&', '<' => '<', '>' => '>', "'" => ''', '"' => '"');
// Check whether content has been read.
if (!empty($xml)) {
$this->debug('Entering soap_parser()');
//$this->debug("DATA DUMP:\n\n$xml");
// Create an XML parser.
$this->parser = xml_parser_create($this->xml_encoding);
// Set the options for parsing the XML data.
//xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
// Set the object for the parser.
xml_set_object($this->parser, &$this);
// Set the element handlers for the parser.
xml_set_element_handler($this->parser, 'start_element', 'end_element');
xml_set_character_data_handler($this->parser, 'character_data');
xml_set_default_handler($this->parser, 'default_handler');
// Parse the XML file.
if (!xml_parse($this->parser, $xml, true)) {
// Display an error message.
$this->debug(sprintf("XML error on line %d: %s", xml_get_current_line_number($this->parser), xml_error_string(xml_get_error_code($this->parser))));
$this->fault = true;
} else {
// get final eval string
$this->eval_str = "\$response = " . trim($this->build_eval($this->root_struct)) . ";";
}
xml_parser_free($this->parser);
} else {
$this->debug("xml was empty, didn't parse!");
}
}
示例9: xml
function xml($encoding = "UTF-8")
{
$this->_parser = xml_parser_create($encoding);
$this->_xml_data = "";
$this->_actual_tag = $this;
xml_set_object($this->_parser, $this);
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($this->_parser, "tag_open", "tag_close");
xml_set_character_data_handler($this->_parser, "tag_data");
xml_set_default_handler($this->_parser, "tag_data");
}
示例10: __construct
/**
* @since 2.0
*/
public function __construct()
{
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 0);
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'handleOpenElement', 'handleCloseElement');
xml_set_character_data_handler($this->parser, 'handleCharacterData');
xml_set_default_handler($this->parser, 'handleDefault');
//xml_set_start_namespace_decl_handler($parser, 'handleNsDeclaration' );
}
示例11: __construct
/**
* Class constructor
*
* @param string The path of the file to parse
* @param string A prefix path to add to all 'src' and 'href' attributes, if relative
* @param string The output charset (default is UTF-8)
* @return void
*/
public function __construct($file, $charset = 'UTF-8')
{
// The charset must be uppercase
$charset = strtoupper($charset);
// Checks if the file exists
if (!file_exists($file) || !is_file($file)) {
// The file does not exist
throw new Woops_Xml_Parser_Exception('The specified XML file (\'' . $file . '\') does not exist', Woops_Xml_Parser_Exception::EXCEPTION_NO_FILE);
}
// Checks if the file is readable
if (!is_readable($file)) {
// Cannot read the file
throw new Woops_Xml_Parser_Exception('The specified XML file (\'' . $file . '\') is not readable', Woops_Xml_Parser_Exception::EXCEPTION_FILE_NOT_READABLE);
}
// Checks if the charset is supported
if (!isset(self::$_charsets[$charset])) {
// Unsupported charset
throw new Woops_Xml_Parser_Exception('The specified charset (' . $charset . ') is not supported', Woops_Xml_Parser_Exception::EXCEPTION_INVALID_CHARSET);
}
// Creates an XML parser
$this->_parser = xml_parser_create($charset);
// Sets the current instance as the XML parser object
xml_set_object($this->_parser, $this);
// Disables case-folding
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
// Sets the element handler methods
xml_set_element_handler($this->_parser, '_startElementHandler', '_endElementHandler');
// Sets the character data handler method
xml_set_character_data_handler($this->_parser, '_characterDataHandler');
// Sets the processing instruction handler method
xml_set_processing_instruction_handler($this->_parser, '_processingInstructionHandler');
// Sets the default data handler method
xml_set_default_handler($this->_parser, '_defaultHandler');
// Tries to open a file handler
if ($fileHandler = fopen($file, 'r')) {
// Reads data from the file
while ($data = fread($fileHandler, 4096)) {
// Tries to parse the data
if (!xml_parse($this->_parser, $data, feof($fileHandler))) {
// Gets the error string and line number
$errorString = xml_error_string(xml_get_error_code($this->_parser));
$errorLine = xml_get_current_line_number($this->_parser);
// Throws an exception, as we have an XML error
throw new Woops_Xml_Parser_Exception('XML parser error: ' . $errorString . ' at line number ' . $errorLine, Woops_Xml_Parser_Exception::EXCEPTION_XML_PARSER_ERROR);
}
}
// Closes the file handler
fclose($fileHandler);
}
// Frees the parser
xml_parser_free($this->_parser);
}
示例12: SaxParser
function SaxParser(&$input)
{
$this->level = 0;
$this->parser = xml_parser_create('UTF-8');
xml_set_object($this->parser, $this);
$this->input =& $input;
$this->setCaseFolding(false);
$this->useUtfEncoding();
xml_set_element_handler($this->parser, 'handleBeginElement', 'handleEndElement');
xml_set_character_data_handler($this->parser, 'handleCharacterData');
xml_set_processing_instruction_handler($this->parser, 'handleProcessingInstruction');
xml_set_default_handler($this->parser, 'handleDefault');
xml_set_unparsed_entity_decl_handler($this->parser, 'handleUnparsedEntityDecl');
xml_set_notation_decl_handler($this->parser, 'handleNotationDecl');
xml_set_external_entity_ref_handler($this->parser, 'handleExternalEntityRef');
}
示例13: parse
function parse($xml)
{
$this->node_list = array(0 => array('type' => 'start', 'children' => array()));
$this->cur_nodeid = 0;
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
xml_set_element_handler($this->parser, array(&$this, 'handle_element_open'), array(&$this, 'handle_element_close'));
xml_set_character_data_handler($this->parser, array(&$this, 'handle_cdata'));
xml_set_processing_instruction_handler($this->parser, array(&$this, 'handle_instruction'));
xml_set_default_handler($this->parser, array(&$this, 'handle_default'));
xml_parse($this->parser, $xml, true);
xml_parser_free($this->parser);
$this->parser = null;
return $this->node_list;
}
示例14: showXML
function showXML($data, $display)
{
if ($display) {
for ($i = 0; $i < $postVars[numHosts]; $i++) {
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_default_handler($xml_parser, "defaultHandler");
echo "<pre>";
if (!xml_parse($xml_parser, $data[$i])) {
die(sprintf("XML error: %s at line %d\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
echo "</pre>";
xml_parser_free($xml_parser);
}
}
}
示例15: makeResultFromXml
/**
* Parse the given XML result and return an SMWSparqlResultWrapper for
* the contained data.
*
* @param $xmlQueryResult string
*/
public function makeResultFromXml($xmlQueryResult)
{
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($parser, $this);
xml_set_element_handler($parser, 'xmlHandleOpen', 'xmlHandleClose');
xml_set_character_data_handler($parser, 'xmlHandleCData');
xml_set_default_handler($parser, 'xmlHandleDefault');
//xml_set_start_namespace_decl_handler($parser, 'xmlHandleNsDeclaration' );
$this->m_xml_opentags = array();
$this->m_header = array();
$this->m_data = array();
$this->m_comments = array();
xml_parse($parser, $xmlQueryResult, true);
xml_parser_free($parser);
return new SMWSparqlResultWrapper($this->m_header, $this->m_data, $this->m_comments);
}