Esempio n. 1
0
 public function correct(string $input) : string
 {
     if (!mb_check_encoding($input, 'UTF-8')) {
         throw new SyntaxException(_('SVGファイルの符号化方式 (文字コード) は UTF-8 でなければなりません。'));
     }
     $parser = xml_parser_create_ns();
     $isValid = xml_parse_into_struct($parser, $input, $nodes);
     xml_parser_free($parser);
     if (!$isValid) {
         throw new SyntaxException(_('整形式になっていません。'));
     }
     $document = new \DOMDocument('1.0', 'UTF-8');
     $document->loadXML($input);
     // ノードの削除
     $root = $document->documentElement;
     foreach ((new \DOMXPath($document))->query(self::BLACKLIST) as $node) {
         if ($node === $root) {
             throw new SyntaxException(_('ルート要素がSVG名前空間に属していません。'));
         }
         $this->logger->error(sprintf(_('SVG中にノード %s を含めることはできません。'), $node->nodeName));
         if ($node->nodeType === XML_ATTRIBUTE_NODE) {
             $node->ownerElement->removeAttributeNode($node);
         } elseif ($node->parentNode) {
             $node->parentNode->removeChild($node);
         }
     }
     return $document->saveXML();
 }
Esempio n. 2
0
 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;
 }
 /**
  * @param $fname
  */
 private function run($fname)
 {
     $parser = xml_parser_create_ns('UTF-8');
     // case folding violates XML standard, turn it off
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
     xml_set_element_handler($parser, array($this, 'rootElementOpen'), false);
     if (file_exists($fname)) {
         $file = fopen($fname, "rb");
         if ($file) {
             do {
                 $chunk = fread($file, 32768);
                 $ret = xml_parse($parser, $chunk, feof($file));
                 if ($ret == 0) {
                     // XML isn't well-formed!
                     fclose($file);
                     xml_parser_free($parser);
                     return;
                 }
             } while (!feof($file));
             fclose($file);
         }
     }
     $this->wellFormed = true;
     xml_parser_free($parser);
 }
 function parse()
 {
     global $app_logging;
     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");
     $contents = "";
     $fp = fopen("php://input", "r");
     while (!feof($fp)) {
         $line = fgets($fp, 4096);
         if ($app_logging) {
             $contents .= $line;
         }
         if (!xml_parse($parser, $line)) {
             log_app("xml_parse_error", "line: {$line}");
             $this->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));
             log_app("xml_parse_error", $this->error);
             return false;
         }
     }
     fclose($fp);
     xml_parser_free($parser);
     log_app("AtomParser->parse()", trim($contents));
     return true;
 }
Esempio n. 5
0
 function _parse_propfind($path)
 {
     $this->success = true;
     $this->depth = 0;
     $this->props = array();
     $had_input = false;
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     $f_in = fopen($path, "r");
     while ($this->success && !feof($f_in)) {
         $line = fgets($f_in);
         if (is_string($line)) {
             $line = trim($line);
             if ($line == "") {
                 continue;
             }
             $had_input = true;
             $this->success &= xml_parse($xml_parser, $line, false);
         }
     }
     if ($had_input) {
         $this->success &= xml_parse($xml_parser, "", true);
     }
     fclose($f_in);
     xml_parser_free($xml_parser);
     if (!count($this->props)) {
         $this->props = "all";
     }
     // default
 }
Esempio n. 6
0
 function _parse_lockinfo($path)
 {
     $this->success = true;
     $had_input = false;
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
     xml_set_character_data_handler($xml_parser, array(&$this, "_data"));
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     $f_in = fopen($path, "r");
     while ($this->success && !feof($f_in)) {
         $line = fgets($f_in);
         if (is_string($line)) {
             $line = trim($line);
             if ($line == "") {
                 continue;
             }
             $had_input = true;
             $this->success &= xml_parse($xml_parser, $line, false);
         }
     }
     if ($had_input) {
         $this->success &= xml_parse($xml_parser, "", true);
     }
     fclose($f_in);
     xml_parser_free($xml_parser);
 }
 /**
  * constructor
  * 
  * @param  string  path of input stream 
  * @access public
  */
 function _parse_proppatch($path)
 {
     $this->success = true;
     $this->depth = 0;
     $this->props = array();
     $had_input = false;
     $f_in = fopen($path, "r");
     if (!$f_in) {
         $this->success = false;
         return;
     }
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
     xml_set_character_data_handler($xml_parser, array(&$this, "_data"));
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     while ($this->success && !feof($f_in)) {
         $line = fgets($f_in);
         if (is_string($line)) {
             $had_input = true;
             $this->success &= xml_parse($xml_parser, $line, false);
         }
     }
     if ($had_input) {
         $this->success &= xml_parse($xml_parser, "", true);
     }
     xml_parser_free($xml_parser);
     fclose($f_in);
 }
 function init() {
   $this->paths=Array(); 
   $this->parser = xml_parser_create_ns("",'^');
   xml_set_object($this->parser,&$this);
   xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
   xml_set_element_handler($this->parser, "_startElement", "_endElement");
   xml_set_character_data_handler($this->parser,"_data");
 }
Esempio n. 9
0
 function createParser()
 {
     $parser = xml_parser_create_ns(NULL, self::NS_SEPARATOR);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, FALSE);
     xml_set_object($parser, $this);
     xml_set_element_handler($parser, 'startElement', 'endElement');
     xml_set_character_data_handler($parser, 'characterData');
     return $parser;
 }
Esempio n. 10
0
 function HTTP_WebDAV_Client_parse_lock_response($response)
 {
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
     xml_set_character_data_handler($xml_parser, array(&$this, "_data"));
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     $this->success = xml_parse($xml_parser, $response, true);
     xml_parser_free($xml_parser);
 }
Esempio n. 11
0
 /**
  * Convert the specified comcode (text format) into a tempcode tree. You shouldn't output the tempcode tree to the browser, as it looks really horrible. If you are in a rare case where you need to output directly (not through templates), you should call the evaluate method on the tempcode object, to convert it into a string.
  *
  * @param  LONG_TEXT		The comcode to convert
  * @param  MEMBER			The member the evaluation is running as. This is a security issue, and you should only run as an administrator if you have considered where the comcode came from carefully
  * @param  ?integer		The position to conduct wordwrapping at (NULL: do not conduct word-wrapping)
  * @param  ?string		A special identifier that can identify this resource in a sea of our resources of this class; usually this can be ignored, but may be used to provide a binding between Javascript in evaluated comcode, and the surrounding environment (NULL: no explicit binding)
  * @param  object			The database connection to use
  * @param  boolean		Whether to parse so as to create something that would fit inside a semihtml tag. It means we generate HTML, with Comcode written into it where the tag could never be reverse-converted (e.g. a block).
  * @param  boolean		Whether this is being pre-parsed, to pick up errors before row insertion.
  * @param  boolean		Whether to treat this whole thing as being wrapped in semihtml, but apply normal security otherwise.
  * @param  boolean		Whether we are only doing this parse to find the title structure
  * @param  boolean		Whether to only check the Comcode. It's best to use the check_comcode function which will in turn use this parameter.
  * @param  ?MEMBER		The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating)
  * @return tempcode		The tempcode tree.
  */
 function comcode_xml_to_tempcode($comcode, $source_member, $wrap_pos, $pass_id, $connection, $semiparse_mode, $preparse_mode, $is_all_semihtml, $structure_sweep, $check_only, $on_behalf_of_member = NULL)
 {
     if (is_null($pass_id)) {
         $pass_id = strval(mt_rand(0, 32000));
     }
     // This is a unique ID that refers to this specific piece of comcode
     $this->wml = false;
     // removed feature from ocPortal now
     $this->comcode = $comcode;
     $this->source_member = $source_member;
     $this->wrap_pos = $wrap_pos;
     $this->pass_id = $pass_id;
     $this->connection = $connection;
     $this->semiparse_mode = $semiparse_mode;
     $this->preparse_mode = $preparse_mode;
     $this->is_all_semihtml = $is_all_semihtml;
     $this->structure_sweep = $structure_sweep;
     $this->check_only = $check_only;
     $this->on_behalf_of_member = $on_behalf_of_member;
     global $VALID_COMCODE_TAGS, $IMPORTED_CUSTOM_COMCODE;
     if (!$IMPORTED_CUSTOM_COMCODE) {
         _custom_comcode_import($connection);
     }
     $this->namespace_stack = array();
     $this->tag_stack = array();
     $this->attribute_stack = array();
     $this->tempcode_stack = array(new ocp_tempcode());
     $this->special_child_elements_stack = array();
     // Create and setup our parser
     $xml_parser = function_exists('xml_parser_create_ns') ? xml_parser_create_ns() : xml_parser_create();
     if ($xml_parser === false) {
         return do_lang_tempcode('XML_PARSING_NOT_SUPPORTED');
         // PHP5 default build on windows comes with this function disabled, so we need to be able to escape on error
     }
     xml_set_object($xml_parser, $this);
     @xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, get_charset());
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
     xml_set_element_handler($xml_parser, 'startElement', 'endElement');
     xml_set_character_data_handler($xml_parser, 'startText');
     if (function_exists('xml_set_start_namespace_decl_handler')) {
         xml_set_start_namespace_decl_handler($xml_parser, 'startNamespace');
     }
     if (function_exists('xml_set_end_namespace_decl_handler')) {
         xml_set_end_namespace_decl_handler($xml_parser, 'startNamespace');
     }
     $extra_data = "<?xml version=\"1.0\" encoding=\"" . escape_html(get_charset()) . "\" ?" . ">\n<!DOCTYPE comcode_xml [\n<!ENTITY nbsp \"&nbsp;\" >\n]>\n";
     if (xml_parse($xml_parser, $extra_data . $comcode, true) == 0) {
         $error_str = xml_error_string(xml_get_error_code($xml_parser));
         warn_exit(escape_html($error_str));
         // Parsing error
     } else {
         $this->tempcode = $this->tempcode_stack[0];
     }
     @xml_parser_free($xml_parser);
     return $this->tempcode;
 }
 private function init_parser()
 {
     $this->depth = -1;
     $this->parser = xml_parser_create_ns("UTF-8", $this->delimiter);
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
     xml_set_character_data_handler($this->parser, array(&$this, "handle_character"));
     xml_set_element_handler($this->parser, array(&$this, "handle_start_tag"), array(&$this, "handle_end_tag"));
 }
Esempio n. 13
0
/**
 * Main entry point for parsing XRDS documents
 */
function xrds_parse($xml)
{
    global $xrds_services;
    $parser = xml_parser_create_ns();
    xml_set_element_handler($parser, '_xrds_element_start', '_xrds_element_end');
    xml_set_character_data_handler($parser, '_xrds_cdata');
    xml_parse($parser, $xml);
    xml_parser_free($parser);
    return $xrds_services;
}
Esempio n. 14
0
 /**
  * Constructor
  */
 function OWLReader()
 {
     $this->root_tag = new OWLTag();
     $this->parser = xml_parser_create_ns();
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
     //KARIM: removed & before "$this->root_tag" since it is not allowed in new versions of PHP
     xml_set_object($this->parser, $this->root_tag);
     xml_set_element_handler($this->parser, "startTag", "endTag");
     xml_set_character_data_handler($this->parser, "characters");
     xml_set_start_namespace_decl_handler($this->parser, "namespaceDecl");
 }
 function __construct($response)
 {
     $this->urls = array();
     $this->_depth = 0;
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     xml_set_element_handler($xml_parser, array($this, "_startElement"), array($this, "_endElement"));
     xml_set_character_data_handler($xml_parser, array($this, "_data"));
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     $this->success = xml_parse($xml_parser, $response, true);
     xml_parser_free($xml_parser);
     unset($this->_depth);
 }
Esempio n. 16
0
 /**
  * Parse the passed XML to create a PHP object.
  *
  * @param string $xml The xml string to parse.
  *
  * @returns mixed A PHP object derived from DTS\eBaySDK\Types\BaseType
  */
 public function parse($xml)
 {
     $parser = xml_parser_create_ns('UTF-8', '@');
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_set_object($parser, $this);
     xml_set_element_handler($parser, 'startElement', 'endElement');
     xml_set_character_data_handler($parser, 'cdata');
     xml_parse($parser, $xml, true);
     xml_parser_free($parser);
     return $this->rootObject;
 }
 /** @ignore */
 protected function initXMLParser()
 {
     if (!isset($this->_xmlParser)) {
         $parser = xml_parser_create_ns('UTF-8', '');
         xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
         xml_set_element_handler($parser, 'startElementHandler', 'endElementHandler');
         xml_set_character_data_handler($parser, 'cdataHandler');
         xml_set_start_namespace_decl_handler($parser, 'newNamespaceHandler');
         xml_set_object($parser, $this);
         $this->_xmlParser = $parser;
     }
 }
 function initXMLParser()
 {
     if (!isset($this->xml_parser)) {
         $enc = preg_match('/^(utf\\-8|iso\\-8859\\-1|us\\-ascii)$/i', $this->getEncoding(), $m) ? $m[1] : 'UTF-8';
         $parser = xml_parser_create_ns($enc, '');
         xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
         xml_set_element_handler($parser, 'open', 'close');
         xml_set_character_data_handler($parser, 'cdata');
         xml_set_start_namespace_decl_handler($parser, 'nsDecl');
         xml_set_object($parser, $this);
         $this->xml_parser = $parser;
     }
 }
Esempio n. 19
0
 function _parse_xsd_file(&$array, $xsdfile)
 {
     $xml_parser = xml_parser_create_ns();
     xml_set_element_handler($xml_parser, array(&$this, '_start_element'), array(&$this, '_end_element'));
     $p = strpos($xsdfile, '_');
     if (!($fp = fopen(APP_DIR . '/' . substr($xsdfile, 0, $p) . '/xmlschema/' . substr($xsdfile, $p + 1) . '.xsd', "r"))) {
         die("could not open XML input:" . $xsdfile);
     }
     while ($data = fread($fp, 4096)) {
         if (!xml_parse($xml_parser, $data, feof($fp))) {
             die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
         }
     }
     xml_parser_free($xml_parser);
 }
Esempio n. 20
0
 private static function ExtractArrayFromXMLString($data)
 {
     $xmlParser = xml_parser_create_ns('UTF-8');
     xml_parser_set_option($xmlParser, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, 0);
     $xmlTags = array();
     $rc = xml_parse_into_struct($xmlParser, $data, $xmlTags);
     if ($rc == false) {
         throw new CDavXMLParsingException(xml_error_string(xml_get_error_code($xmlParser)), xml_get_current_line_number($xmlParser), xml_get_current_column_number($xmlParser));
     }
     xml_parser_free($xmlParser);
     if (count($xmlTags) == 0) {
         $xmlTags = null;
     }
     return $xmlTags;
 }
Esempio n. 21
0
 /**
  * Take the input $xml and turn it into WBXML. This is _not_ the
  * intended way of using this class. It is derived from
  * Contenthandler and one should use it as a ContentHandler and
  * produce the XML-structure with startElement(), endElement(),
  * and characters().
  *
  * @throws Horde_Xml_Wbxml_Exception
  */
 public function encode($xml)
 {
     // Create the XML parser and set method references.
     $this->_parser = xml_parser_create_ns($this->_charset);
     xml_set_object($this->_parser, $this);
     xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
     xml_set_element_handler($this->_parser, '_startElement', '_endElement');
     xml_set_character_data_handler($this->_parser, '_characters');
     xml_set_processing_instruction_handler($this->_parser, '');
     xml_set_external_entity_ref_handler($this->_parser, '');
     if (!xml_parse($this->_parser, $xml)) {
         throw new Horde_Xml_Wbxml_Exception(sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)));
     }
     xml_parser_free($this->_parser);
     return $this->_output;
 }
 /**
  * constructor
  *
  * @access public
  */
 function _parse_propfind($path)
 {
     // success state flag
     $this->success = true;
     // property storage array
     $this->props = array();
     // internal tag depth counter
     $this->depth = 0;
     // remember if any input was parsed
     $had_input = false;
     // open input stream
     $f_in = fopen($path, "r");
     if (!$f_in) {
         $this->success = false;
         return;
     }
     // create XML parser
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     // set tag and data handlers
     xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
     // we want a case sensitive parser
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     // parse input
     while ($this->success && !feof($f_in)) {
         $line = fgets($f_in);
         if (is_string($line)) {
             $had_input = true;
             $this->success &= xml_parse($xml_parser, $line, false);
         }
     }
     // finish parsing
     if ($had_input) {
         $this->success &= xml_parse($xml_parser, "", true);
     }
     // free parser
     xml_parser_free($xml_parser);
     // close input stream
     fclose($f_in);
     // if no input was parsed it was a request
     if (!count($this->props)) {
         $this->props = "all";
     }
     // default
 }
Esempio n. 23
0
 protected final function init()
 {
     if ($this instanceof Features\IXmlNamespaceParser) {
         $this->parser = xml_parser_create_ns('UTF-8');
         // Set up start namespace declaration handler
         xml_set_start_namespace_decl_handler($this->parser, 'ns_start');
         // Set up end namespace declaration handler
         xml_set_end_namespace_decl_handler($this->parser, 'ns_end');
     } elseif ($this instanceof Features\IXmlBasicParser) {
         $this->parser = xml_parser_create('UTF-8');
     } else {
         throw new \BadMethodCallException('This class does not implements the XML Parser capabilities. Please implement either IXmlBasicParser or IXmlNamespaceParser.');
     }
     xml_set_object($this->parser, $this);
     foreach ($this->options as $option => $value) {
         xml_parser_set_option($this->parser, $option, $value);
     }
     if ($this instanceof Features\IXmlProcessorParser) {
         // Set up processing instruction (PI) handler
         xml_set_processing_instruction_handler($this->parser, 'pi_handler');
     }
     if ($this instanceof Features\IXmlEntityHandler) {
         // Set up external entity reference handler
         xml_set_external_entity_ref_handler($this->parser, 'entity_handler');
     }
     if ($this instanceof Features\IXmlNdataHandler) {
         // Set up notation declaration handler
         xml_set_notation_decl_handler($this->parser, 'notation_handler');
         // Set up unparsed entity declaration handler
         xml_set_unparsed_entity_decl_handler($this->parser, 'ndata_handler');
     }
     xml_set_element_handler($this->parser, "element_start", "element_end");
     xml_set_character_data_handler($this->parser, "cdata_handler");
     if ($this instanceof Features\IXmlDefaultHandler) {
         if (!defined('ACTIVATE_XML_PARSER_DEFAULT_HANDLER_I_KNOW_WHAT_AM_I_DOING')) {
             trigger_error('Active default handler interferes with many XML features like internal parsable entities.', E_USER_WARNING);
         }
         // Set up default (fallback) handler.
         // Warning: Interferes with INTERNAL ENTITY declarations like
         // <!ENTITY a 'b'>
         xml_set_default_handler($this->parser, "default_handler");
     }
 }
Esempio n. 24
0
function fetch_remote_list($base_url)
{
    global $request;
    $result = array();
    $list_url = $base_url . '?action=list';
    printf("Fetching timezone list\n", $list_url);
    $raw_xml = file_get_contents($list_url);
    $xml_parser = xml_parser_create_ns('UTF-8');
    $xml_tags = array();
    xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
    $rc = xml_parse_into_struct($xml_parser, $raw_xml, $xml_tags);
    if ($rc == false) {
        dbg_error_log('ERROR', 'XML parsing error: %s at line %d, column %d', xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser));
        $request->PreconditionFailed(400, 'invalid-xml', sprintf('XML parsing error: %s at line %d, column %d', xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser)));
    }
    xml_parser_free($xml_parser);
    $position = 0;
    return BuildXMLTree($xml_tags, $position);
}
Esempio n. 25
0
 function _parse_xsd_file($xsdfile)
 {
     $xml_parser = xml_parser_create_ns();
     xml_set_element_handler($xml_parser, array(&$this, '_start_element'), array(&$this, '_end_element'));
     $p = strpos($xsdfile, '_');
     if (defined('CUSTOM_CORE_DIR') && file_exists(CUSTOM_CORE_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file)) {
         $xmldir = CUSTOM_CORE_DIR . '/' . substr($xsdfile, 0, $p) . '/xmlschema/' . substr($xsdfile, $p + 1) . '.xsd';
     } else {
         $xmldir = APP_DIR . '/' . substr($xsdfile, 0, $p) . '/xmlschema/' . substr($xsdfile, $p + 1) . '.xsd';
     }
     if (!($fp = fopen($xmldir, "r"))) {
         die("could not open XML input:" . $xsdfile);
     }
     while ($data = fread($fp, 4096)) {
         if (!xml_parse($xml_parser, $data, feof($fp))) {
             die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
         }
     }
     xml_parser_free($xml_parser);
 }
 public static function xml2array($xml)
 {
     $parser = xml_parser_create_ns();
     $foldingOptionSet = xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     if (!$foldingOptionSet) {
         throw new EngineBlock_Corto_XmlToArray_Exception("Unable to set XML_OPTION_CASE_FOLDING on parser object? Error message: " . xml_error_string(xml_get_error_code($parser)), EngineBlock_Corto_XmlToArray_Exception::CODE_ERROR);
     }
     $values = array();
     $parserResultStatus = xml_parse_into_struct($parser, $xml, $values);
     if ($parserResultStatus !== 1) {
         $errorCode = xml_get_error_code($parser);
         $errorMessage = xml_error_string($errorCode);
         throw new EngineBlock_Corto_XmlToArray_Exception('Error parsing incoming XML. ' . PHP_EOL . 'Error code: ' . $errorCode . PHP_EOL . 'Error message: ' . $errorMessage . PHP_EOL . 'Last libXML error: ' . var_export(libxml_get_last_error(), true) . PHP_EOL . 'XML: ' . $xml);
     }
     xml_parser_free($parser);
     self::$_singulars = array_fill_keys(self::$_singulars, 1);
     $return = self::_xml2array($values);
     self::$_singulars = array_keys(self::$_singulars);
     return $return[0];
 }
Esempio n. 27
0
 /**
  * constructor
  *
  * @param  string  path of stream to read
  * @access public
  */
 function _parse_lockinfo($path)
 {
     // we assume success unless problems occur
     $this->success = true;
     // remember if any input was parsed
     $had_input = false;
     // open stream
     $f_in = fopen($path, "r");
     if (!$f_in) {
         $this->success = false;
         return;
     }
     // create namespace aware parser
     $xml_parser = xml_parser_create_ns("UTF-8", " ");
     // set tag and data handlers
     xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
     xml_set_character_data_handler($xml_parser, array(&$this, "_data"));
     // we want a case sensitive parser
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     // parse input
     while ($this->success && !feof($f_in)) {
         $line = fgets($f_in);
         if (is_string($line)) {
             $had_input = true;
             $this->success &= xml_parse($xml_parser, $line, false);
         }
     }
     // finish parsing
     if ($had_input) {
         $this->success &= xml_parse($xml_parser, "", true);
     }
     // check if required tags where found
     $this->success &= !empty($this->locktype);
     $this->success &= !empty($this->lockscope);
     // free parser resource
     xml_parser_free($xml_parser);
     // close input stream
     fclose($f_in);
 }
Esempio n. 28
0
 /**
  * reads an xml file, parses it into a structure
  * constructor
  * @param String file the xml file to read
  * @return XmlReader
  * @access public
  */
 function XmlReader2($file)
 {
     $requested_file = $file;
     #the given path can be a absolute path
     #if it's not a file, look in the default CMS xml directory and the default xml directory for the given file
     if (is_file($file)) {
         $file = $file;
     } elseif (is_file(CMS_XML_PATH . $file)) {
         $file = CMS_XML_PATH . $file;
     } else {
         $file = XML_PATH . $file;
     }
     $s = simplexml_load_file($file);
     #if the file still does not exist, raise error
     //if(!is_array($file))
     //New ErrorHandler(get_class($this), "constructor", "", "FILE DOES NOT EXIST", "The file does not exist: $requested_file");
     $parser = xml_parser_create_ns("ISO-8859-1");
     if (!($fp = fopen($file, "r"))) {
         die("could not open XML input");
     }
     $data = fread($fp, filesize($file));
     fclose($fp);
     #this is how a complete node looks like, when unnecessary data is excluded:
     #Array ( [tag] => PAGE [type] => open [level] => 2 [value] => [node] => 1 )
     #Array ( [tag] => PAGENAME [type] => complete [level] => 3 [value] => billing [node] => 2 )
     #Array ( [tag] => PAGERIGHT [type] => complete [level] => 3 [value] => all [node] => 3 )
     #Array ( [tag] => PAGEAUTHORIZE [type] => complete [level] => 3 [value] => 0 [node] => 4 )
     #Array ( [tag] => PAGETITLE [type] => complete [level] => 3 [value] => Billing [node] => 5 )
     #Array ( [tag] => PAGEFRAME [type] => complete [level] => 3 [value] => body [node] => 6 )
     #Array ( [tag] => PAGEDEFAULT [type] => complete [level] => 3 [value] => 0 [node] => 7 )
     #Array ( [tag] => PAGE [type] => close [level] => 2 [node] => 8 )
     $p = xml_parse_into_struct($parser, $data, $values, $tags);
     xml_parser_free($parser);
     print_r($s);
     $this->_struct = $values;
     #exclude every array where the key is "type" and the value is "cdata"
     #for more details see the function exclude()
     $this->_excluded = $this->exclude('type', 'cdata');
 }
Esempio n. 29
0
 /**
  * Parses the XML data and returns a multidimensional array (aka tree).
  * Optionally it will also clear the tree and remove nested single arrays
  * and link the values to the parent directly instead.
  *
  * @param string $xml the XML to parse
  * @param bool $destroy_single_arrays whether to keep nested single arrays or not
  * @return bool|array
  * @access public
  * @since 1.0
  * @throws ErrorException
  */
 public function parseByData($xml)
 {
     if (!is_string($xml) || strlen($xml) == 0) {
         throw new ErrorException(self::DATA_NOT_XML);
     }
     /* Create a parser and set the options */
     $parser = xml_parser_create_ns();
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     xml_set_object($parser, $this);
     xml_set_element_handler($parser, 'startElement', 'endElement');
     xml_set_character_data_handler($parser, 'getElement');
     /**
      * Workaround the XML-parser not being able to handle HTML-entities by
      * encapsulating them as CDATA.
      */
     $pattern = '/(&(?:(?!quot|amp|apos|lt|gt)([a-z]+)|(#\\d+));)/iU';
     $replace = '<![CDATA[\\1]]>';
     $xml = preg_replace($pattern, $replace, $xml);
     /* Parse the data and free the parser resource. */
     if (!xml_parse($parser, $xml, true)) {
         $error = "\n\nError code: " . xml_get_error_code($parser) . "\n";
         $error .= "Line: " . xml_get_current_line_number($parser) . ", character: " . xml_get_current_column_number($parser) . "\n";
         $error .= "Error message: " . xml_error_string(xml_get_error_code($parser)) . "\n";
         xml_parser_free($parser);
         throw new ErrorException(self::PARSER_ERROR . $error);
     }
     xml_parser_free($parser);
     /**
      * The root element will contain an array with an empty key, so we can
      * skip that one right now.
      */
     $tree = $this->_tree[''];
     $this->simplifyArray($tree);
     return $tree;
 }
Esempio n. 30
0
 /**
  * Main use is if a single item has multiple xmp documents describing it.
  * For example in jpeg's with extendedXMP
  */
 private function resetXMLParser()
 {
     if ($this->xmlParser) {
         //is this needed?
         xml_parser_free($this->xmlParser);
     }
     $this->xmlParser = xml_parser_create_ns('UTF-8', ' ');
     xml_parser_set_option($this->xmlParser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($this->xmlParser, XML_OPTION_SKIP_WHITE, 1);
     xml_set_element_handler($this->xmlParser, array($this, 'startElement'), array($this, 'endElement'));
     xml_set_character_data_handler($this->xmlParser, array($this, 'char'));
 }