Magento 2 : How can i read Xml file data












1














I have product file in xml format. I just need to read this file and import those data.



I have already use simplexml_load_file(file path) but it will work only small size of file. Is there any other way to read this large xml file ?










share|improve this question





























    1














    I have product file in xml format. I just need to read this file and import those data.



    I have already use simplexml_load_file(file path) but it will work only small size of file. Is there any other way to read this large xml file ?










    share|improve this question



























      1












      1








      1







      I have product file in xml format. I just need to read this file and import those data.



      I have already use simplexml_load_file(file path) but it will work only small size of file. Is there any other way to read this large xml file ?










      share|improve this question















      I have product file in xml format. I just need to read this file and import those data.



      I have already use simplexml_load_file(file path) but it will work only small size of file. Is there any other way to read this large xml file ?







      magento2 xml data-migration product-import






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 8 '18 at 9:35









      Pramod Kharade

      1,586927




      1,586927










      asked Feb 8 '18 at 8:13









      Camit1dkCamit1dk

      381117




      381117






















          2 Answers
          2






          active

          oldest

          votes


















          0














          You can try this way :



           namespace VendorModuleNameModel;  
          class ParseXmlClass
          {
          /**
          * @var MagentoFrameworkModuleDirReader
          */
          protected $moduleDirReader;

          /**
          * @var MagentoFrameworkXmlParser
          */
          private $parser;

          ...

          public function getValue()
          {
          $filePath = $this->moduleDirReader->getModuleDir('etc', 'ModuleName')
          . '/yourxml.xml'
          $parsedArray = $this->parser->load($filePath)->xmlToArray();
          return $parsedArray['xmlNodeName'];
          }
          }





          share|improve this answer





















          • my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
            – Camit1dk
            Feb 8 '18 at 8:56










          • issue only getting while reading large file around 184MB xml file size
            – Camit1dk
            Feb 8 '18 at 8:58










          • If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
            – Shashank Gupta
            Feb 8 '18 at 9:31












          • Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
            – Shashank Gupta
            Feb 8 '18 at 9:36





















          0














          Totally shooting form the hip here, but have you tried PHP's XMLReader or DOMDocument instead of SimpleXML? SimpleXML loads the full document to memory, while the other two do not.






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f212670%2fmagento-2-how-can-i-read-xml-file-data%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can try this way :



             namespace VendorModuleNameModel;  
            class ParseXmlClass
            {
            /**
            * @var MagentoFrameworkModuleDirReader
            */
            protected $moduleDirReader;

            /**
            * @var MagentoFrameworkXmlParser
            */
            private $parser;

            ...

            public function getValue()
            {
            $filePath = $this->moduleDirReader->getModuleDir('etc', 'ModuleName')
            . '/yourxml.xml'
            $parsedArray = $this->parser->load($filePath)->xmlToArray();
            return $parsedArray['xmlNodeName'];
            }
            }





            share|improve this answer





















            • my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
              – Camit1dk
              Feb 8 '18 at 8:56










            • issue only getting while reading large file around 184MB xml file size
              – Camit1dk
              Feb 8 '18 at 8:58










            • If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
              – Shashank Gupta
              Feb 8 '18 at 9:31












            • Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
              – Shashank Gupta
              Feb 8 '18 at 9:36


















            0














            You can try this way :



             namespace VendorModuleNameModel;  
            class ParseXmlClass
            {
            /**
            * @var MagentoFrameworkModuleDirReader
            */
            protected $moduleDirReader;

            /**
            * @var MagentoFrameworkXmlParser
            */
            private $parser;

            ...

            public function getValue()
            {
            $filePath = $this->moduleDirReader->getModuleDir('etc', 'ModuleName')
            . '/yourxml.xml'
            $parsedArray = $this->parser->load($filePath)->xmlToArray();
            return $parsedArray['xmlNodeName'];
            }
            }





            share|improve this answer





















            • my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
              – Camit1dk
              Feb 8 '18 at 8:56










            • issue only getting while reading large file around 184MB xml file size
              – Camit1dk
              Feb 8 '18 at 8:58










            • If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
              – Shashank Gupta
              Feb 8 '18 at 9:31












            • Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
              – Shashank Gupta
              Feb 8 '18 at 9:36
















            0












            0








            0






            You can try this way :



             namespace VendorModuleNameModel;  
            class ParseXmlClass
            {
            /**
            * @var MagentoFrameworkModuleDirReader
            */
            protected $moduleDirReader;

            /**
            * @var MagentoFrameworkXmlParser
            */
            private $parser;

            ...

            public function getValue()
            {
            $filePath = $this->moduleDirReader->getModuleDir('etc', 'ModuleName')
            . '/yourxml.xml'
            $parsedArray = $this->parser->load($filePath)->xmlToArray();
            return $parsedArray['xmlNodeName'];
            }
            }





            share|improve this answer












            You can try this way :



             namespace VendorModuleNameModel;  
            class ParseXmlClass
            {
            /**
            * @var MagentoFrameworkModuleDirReader
            */
            protected $moduleDirReader;

            /**
            * @var MagentoFrameworkXmlParser
            */
            private $parser;

            ...

            public function getValue()
            {
            $filePath = $this->moduleDirReader->getModuleDir('etc', 'ModuleName')
            . '/yourxml.xml'
            $parsedArray = $this->parser->load($filePath)->xmlToArray();
            return $parsedArray['xmlNodeName'];
            }
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 8 '18 at 8:22









            Shashank GuptaShashank Gupta

            481412




            481412












            • my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
              – Camit1dk
              Feb 8 '18 at 8:56










            • issue only getting while reading large file around 184MB xml file size
              – Camit1dk
              Feb 8 '18 at 8:58










            • If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
              – Shashank Gupta
              Feb 8 '18 at 9:31












            • Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
              – Shashank Gupta
              Feb 8 '18 at 9:36




















            • my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
              – Camit1dk
              Feb 8 '18 at 8:56










            • issue only getting while reading large file around 184MB xml file size
              – Camit1dk
              Feb 8 '18 at 8:58










            • If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
              – Shashank Gupta
              Feb 8 '18 at 9:31












            • Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
              – Shashank Gupta
              Feb 8 '18 at 9:36


















            my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
            – Camit1dk
            Feb 8 '18 at 8:56




            my code is stuck at line : $this->parser->load. i have not getting false or true value in xml object
            – Camit1dk
            Feb 8 '18 at 8:56












            issue only getting while reading large file around 184MB xml file size
            – Camit1dk
            Feb 8 '18 at 8:58




            issue only getting while reading large file around 184MB xml file size
            – Camit1dk
            Feb 8 '18 at 8:58












            If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
            – Shashank Gupta
            Feb 8 '18 at 9:31






            If you are not getting true and false from code and also there is no error it mean's the script is running , So I would recommend to do following : 1. Increase max execution time and and max post file size , by default it set to 2 MB increase to 512 MB in php.ini 2. If possible increase you server CPU or RAM it will help you for faster execution . Hope solution will work for you .
            – Shashank Gupta
            Feb 8 '18 at 9:31














            Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
            – Shashank Gupta
            Feb 8 '18 at 9:36






            Find following value in php.ini post_max_size = 512M upload_max_filesize = 256M memory_limit = 2048M Then run following command sudo service apache2 restart (if you are using apache2) sudo service httpd restart (if you are using nginx)
            – Shashank Gupta
            Feb 8 '18 at 9:36















            0














            Totally shooting form the hip here, but have you tried PHP's XMLReader or DOMDocument instead of SimpleXML? SimpleXML loads the full document to memory, while the other two do not.






            share|improve this answer


























              0














              Totally shooting form the hip here, but have you tried PHP's XMLReader or DOMDocument instead of SimpleXML? SimpleXML loads the full document to memory, while the other two do not.






              share|improve this answer
























                0












                0








                0






                Totally shooting form the hip here, but have you tried PHP's XMLReader or DOMDocument instead of SimpleXML? SimpleXML loads the full document to memory, while the other two do not.






                share|improve this answer












                Totally shooting form the hip here, but have you tried PHP's XMLReader or DOMDocument instead of SimpleXML? SimpleXML loads the full document to memory, while the other two do not.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                siliconrockstarsiliconrockstar

                1548




                1548






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f212670%2fmagento-2-how-can-i-read-xml-file-data%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    1300-talet

                    1300-talet

                    Has there ever been an instance of an active nuclear power plant within or near a war zone?