Huge input lookup xml как исправить

I am using PHP for the first time. I am getting the following error on running the PHP file:

PHP Warning:  simplexml_load_string(): Entity: line 35909: parser error : internal error: Huge input lookup in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 8

PHP Warning:  simplexml_load_string(): p;lt;img src="/UserFiles/FCK/image/prima hangisi(1).jpg" class in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 8

PHP Warning:  simplexml_load_string():                                                                                ^ in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 8

PHP Fatal error:  Call to a member function children() on boolean in /home/alisverispasaji/public_html/system/xml/minikoli/test.php on line 20

How I can solve this error?

test.php:

<?php
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0) Gecko/20100101 Firefox/9.0');
error_reporting(-1);

function simplexml_load_file_curl($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $xml = simplexml_load_string(curl_exec($ch)); // <--- line 8
    return $xml;
}

$url = 'xml link';

$xml = simplexml_load_file_curl($url);

$veri = '<?xml version="1.0" encoding="UTF-8"?>';
$veri .= '
<Urunler>';

foreach($xml->children() as $urun) { // <--- line 20

IMSoP's user avatar

IMSoP

87.6k13 gold badges115 silver badges168 bronze badges

asked Mar 31, 2017 at 6:35

Ümit BÜKÇÜOĞLU's user avatar

3

Problem Solved

Find ;

$xml = simplexml_load_string(curl_exec($ch));

Change ;

$xml = simplexml_load_string(curl_exec($ch), 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);

answered Mar 31, 2017 at 12:10

Ümit BÜKÇÜOĞLU's user avatar

Ümit BÜKÇÜOĞLUÜmit BÜKÇÜOĞLU

3111 gold badge2 silver badges6 bronze badges

0

stur 20.12.2017 18:50
/ 20.12.2017 18:51

Столкнулись с проблемой обработки больших xml файлов.
Как только файл около 10 Мб, на

xdoc::create

выдаётся исключение:

Entity: line xxx: parser error : internal error: Huge input lookup

Кто-нибудь сталкивался?

Видел пишут про XML_PARSE_HUGE при сборке libxml, но хотел сперва уточнить тут, может кто-то сталкивался и владеет информацией, что делать :)


  • libxml проблема обработки больших xml, stur 20.12.2017 18:50 / 20.12.2017 18:51
    • Ответ, G_Z [M] 21.12.2017 03:25 / 21.12.2017 05:31
      • так и есть, stur 21.12.2017 07:32
    • Ответ, MoKo 21.12.2017 01:49
      • атрибуты на node, stur 21.12.2017 08:18
        • Там достаточно странно., MoKo 22.12.2017 05:05
          • отлично, спасибо! (-), stur 22.12.2017 09:07 / 22.12.2017 09:15
      • Ответ, stur 21.12.2017 07:28
        • Ответ, MoKo 22.12.2017 04:56
          • Ответ, stur 22.12.2017 09:14

Prerequisites

  • [ x] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • [ x] Checked that your issue isn’t already filed.
  • [ x] Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.1.5
  • Laravel version: 5.7
  • Package version: 3.1

Description

On large xlsx imports (over 10mb) I get an error of simplexml_load_string(): internal error: Huge input lookup
I set up an xlsx file import using ToCollectionon v3.1 and it works very well until I try to upload a file over 10MB (my file has 116,000 xlsx rows), at which point, I receive the following error:
simplexml_load_string(): Entity: line 2: parser error : internal error: Huge input lookup

I found a temp fix but I am searching for a permanent fix.
After doing some digging, I found that the error is generated because «Since version 2.7.3 libxml limits the maximum size of a single text node to 10MB».
https://stackoverflow.com/questions/5428055/xml-parse-huge-on-function-simplexml-load-string

— but the limit can be overridden by setting the flag XML_PARSE_HUGE at the time when the default options for the libxml loader are set.

To find where the options can be set I dug down in to the package’s own dependency of PhpOffice/PhpSpreadsheet

/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx.php:759

As a test, I can temporarily fix the problem in the vendor code and I get my import to work by adding the XML_PARSE_HUGE option 1) either right at line 759 or 2) its seems that a better location is to fix/add the option in the Settings file:

/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Settings:81

by adding this line:

$options = LIBXML_COMPACT | LIBXML_PARSEHUGE;
(see: PHPOffice/PhpSpreadsheet#391)

above the existing code:

if ($options === null && defined(‘LIBXML_DTDLOAD’)) {

        $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
    }
    self::$libXmlLoaderOptions = $options;

As a permanent solution I have tried to extend/override the settings file from my code but I have not been successful at finding a way to do it.

Any suggestions on how to override would be much appreciated. Also, I have outlined my research into the problem above so that it might help anybody else who has the same issue.

Finally, it would be great if this flag could be an option in the package’s config.excel file.

Thanks in advance for any help you might provide on this issue.

Steps to Reproduce

Import an xlsx file larger than 10mb

Expected behavior:

Actual behavior:

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

I have an IOS app where I need to parse an xml file and I’ve been working with NSXMLParser. I have some xml data that about 8kbytes and Im getting this error, but Im parsing smaller files without an issue. I’ve tried searching and I couldn’t find anyone else with this problem in IOS. Is this a limitation of NSXMLParser and I need to use a different library or is there some property that has to be set to allow for larger data?

Any help would be appreciated.

EDIT:
Here is the file exactly as I’m retrieving from my web service: https://www.dropbox.com/s/3436w653reyybpb/File.xml

Here is the code Im using:

// XML.m
- (id)parseXml:(NSData *)data
{
    NSXMLParser *xml = [[NSXMLParser alloc] initWithData:data];
    xml.delegate = self;
    results = [[NSMutableArray alloc] init];
    error = nil;
    [xml parse];
    if (error) return error;
    return results;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    [results addObject:attributeDict];
}
- (void) parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
    error = parseError;
}

The code isn’t even reaching the didStartElement delegate method, it’s just going right to the parseErrorOccured. The data thats being passed is the file contents that I supplied.

asked Nov 24, 2013 at 17:39

Brian Tacker's user avatar

Brian TackerBrian Tacker

1,0912 gold badges18 silver badges37 bronze badges

7

The xml:

<?xml version="1.0" encoding="utf-16"?>

specifies that it is utf-16 but it is actually utf-8

answered Nov 25, 2013 at 3:42

zaph's user avatar

zaphzaph

112k21 gold badges189 silver badges227 bronze badges

4

As Zaph said, the issue is that it is not utf-16. In the future, if the NSXMLParser error message is not clear enough, you can try running this through xmllint at the Terminal command line. In this case, it reports:

$ xmllint File.xml 
File.xml:1: parser error : Document labelled UTF-16 but has UTF-8 content
<?xml version="1.0" encoding="utf-16"?><Response Error=""><RX RxNumber="11684600
                                     ^

answered Nov 28, 2013 at 16:39

Rob's user avatar

RobRob

411k71 gold badges776 silver badges1033 bronze badges

1

Есть некий xml файл, весит больше 1ГБ, минифицированный.
Я восстановил кусочек в начале для понимания схемы

spoiler

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tns:INSPECTIONS xmlns:tns="ссылка" YEAR="2020" MONTH="1">

    <tns:INSPECTION данные>
        <tns:OKATO FEDERAL_DISTRICT="" данные/>
        <tns:I_OBJECT ADDRESS="" данные>
            <tns:I_RESULT ACT_DATE_CREATE="" данные>
                <tns:I_RESULT_INSPECTOR FULL_NAME="" данные />
                <tns:I_VIOLATION IVIOLATION_TYPE_NAME="" данные>
                    <tns:V_INJUNCTION CODE="" данные />
                </tns:I_VIOLATION>
            </tns:I_RESULT>
        </tns:I_OBJECT>
        <tns:I_SUBJECT IS_RESIDENT="" данные />
        <tns:I_CLASSIFICATION ICARRYOUT_TYPE_NAME="" данные />
        <tns:I_AUTHORITY FRGU_ORG_ID_BK="" данные/>
        <tns:I_APPROVE START_DATE="" данные>
            <tns:I_APPROVE_DOCS IAPPROVE_DOC_NAME="" данные />
        </tns:I_APPROVE>
    </tns:INSPECTION>

</tns:INSPECTIONS>

Если загрузить файл через simplexml_load_file(), то в итоге получаю только атрибуты YEAR=»2020″ MONTH=»1″ (в поле @attributes), а полей как-бы никаких нет…

Попробовал заменить все tns: на пустоту, simplexml_load_string() выдает internal error: Huge input lookup, добавил опцию LIBXML_PARSEHUGE, получаю ошибку simplexml_load_string(): Memory allocation failed : growing input buffer

Как корректно работать с таким файлом?

Понравилась статья? Поделить с друзьями:

Не пропустите также:

  • Как найти женщину заниматься сексом с
  • Как составить уравнение прямой через координаты вектора
  • Как найти баллы егэ прошлых лет
  • Как найти дельта давление в физике
  • Как составить часть б в тесте

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии