<bdo id='1C1oK'></bdo><ul id='1C1oK'></ul>
      <i id='1C1oK'><tr id='1C1oK'><dt id='1C1oK'><q id='1C1oK'><span id='1C1oK'><b id='1C1oK'><form id='1C1oK'><ins id='1C1oK'></ins><ul id='1C1oK'></ul><sub id='1C1oK'></sub></form><legend id='1C1oK'></legend><bdo id='1C1oK'><pre id='1C1oK'><center id='1C1oK'></center></pre></bdo></b><th id='1C1oK'></th></span></q></dt></tr></i><div id='1C1oK'><tfoot id='1C1oK'></tfoot><dl id='1C1oK'><fieldset id='1C1oK'></fieldset></dl></div>
      <legend id='1C1oK'><style id='1C1oK'><dir id='1C1oK'><q id='1C1oK'></q></dir></style></legend>
      1. <tfoot id='1C1oK'></tfoot>
      2. <small id='1C1oK'></small><noframes id='1C1oK'>

        在 PHP 中流解析 4 GB XML 文件

        Stream parse 4 GB XML file in PHP(在 PHP 中流解析 4 GB XML 文件)
          <tbody id='2KwBY'></tbody>
      3. <tfoot id='2KwBY'></tfoot>
              <bdo id='2KwBY'></bdo><ul id='2KwBY'></ul>

                  <legend id='2KwBY'><style id='2KwBY'><dir id='2KwBY'><q id='2KwBY'></q></dir></style></legend>

                  <small id='2KwBY'></small><noframes id='2KwBY'>

                • <i id='2KwBY'><tr id='2KwBY'><dt id='2KwBY'><q id='2KwBY'><span id='2KwBY'><b id='2KwBY'><form id='2KwBY'><ins id='2KwBY'></ins><ul id='2KwBY'></ul><sub id='2KwBY'></sub></form><legend id='2KwBY'></legend><bdo id='2KwBY'><pre id='2KwBY'><center id='2KwBY'></center></pre></bdo></b><th id='2KwBY'></th></span></q></dt></tr></i><div id='2KwBY'><tfoot id='2KwBY'></tfoot><dl id='2KwBY'><fieldset id='2KwBY'></fieldset></dl></div>

                • 本文介绍了在 PHP 中流解析 4 GB XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试并需要一些帮助来执行以下操作:

                  I'm trying and need some help doing the following:

                  我想用 PHP 流式解析一个大的 XML 文件(4 GB).我不能使用简单的 XML 或 DOM,因为它们会将整个文件加载到内存中,所以我需要可以流式传输文件的东西.

                  I want to stream parse a large XML file ( 4 GB ) with PHP. I can't use simple XML or DOM because they load the entire file into memory, so I need something that can stream the file.

                  我如何在 PHP 中做到这一点?

                  How can I do this in PHP?

                  我要做的是浏览一系列 <doc> 元素.并将他们的一些孩子写入一个新的 xml 文件.

                  What I am trying to do is to navigate through a series of <doc> elements. And write some of their children to a new xml file.

                  我尝试解析的 XML 文件如下所示:

                  The XML file I am trying to parse looks like this:

                  <feed>
                      <doc>
                          <title>Title of first doc is here</title>
                          <url>URL is here</url>
                          <abstract>Abstract is here...</abstract>
                          <links>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                         </link>
                      </doc>
                      <doc>
                          <title>Title of second doc is here</title>
                          <url>URL is here</url>
                          <abstract>Abstract is here...</abstract>
                          <links>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                              <sublink>Link is here</sublink>
                         </link>
                      </doc>
                  </feed>
                  

                  我正在尝试获取/复制每个 <doc> 元素的所有子元素到一个新的 XML 文件中,除了 <links> 元素及其子元素.

                  I'm trying to get / copy all the children of each <doc> element into a new XML file except the <links> element and its children.

                  所以我希望新的 XML 文件看起来像:

                  So I want the new XML file to look like:

                  <doc>
                      <title>Title of first doc is here</title>
                      <url>URL is here</url>
                      <abstract>Abstract is here...</abstract>
                  </doc>
                  <doc>
                      <title>Title of second doc is here</title>
                      <url>URL is here</url>
                      <abstract>Abstract is here...</abstract>
                  </doc>
                  

                  我非常感谢流/流解析/流读取原始 XML 文件,然后将其部分内容写入 PHP 中的新 XML 文件.

                  推荐答案

                  这是一个大学尝试.这假设正在使用一个文件,并且您想要写入一个文件:

                  Here's a college try. This assumes a file is being used, and that you want to write to a file:

                  <?php
                  
                  $interestingNodes = array('title','url','abstract');
                  $xmlObject = new XMLReader();
                  $xmlObject->open('bigolfile.xml');
                  
                  $xmlOutput = new XMLWriter();
                  $xmlOutput->openURI('destfile.xml');
                  $xmlOutput->setIndent(true);
                  $xmlOutput->setIndentString("   ");
                  $xmlOutput->startDocument('1.0', 'UTF-8');
                  
                  while($xmlObject->read()){
                      if($xmlObject->name == 'doc'){
                          $xmlOutput->startElement('doc');
                          $xmlObject->readInnerXML();
                          if(array_search($xmlObject->name, $interestingNodes)){
                               $xmlOutput->startElement($xmlObject->name);
                               $xmlOutput->text($xmlObject->value);
                               $xmlOutput->endElement(); //close the current node
                          }
                          $xmlOutput->endElement(); //close the doc node
                      }
                  }
                  
                  $xmlObject->close();
                  $xmlOutput->endDocument();
                  $xmlOutput->flush();
                  
                  ?>
                  

                  这篇关于在 PHP 中流解析 4 GB XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <legend id='QS1JY'><style id='QS1JY'><dir id='QS1JY'><q id='QS1JY'></q></dir></style></legend>

                  <small id='QS1JY'></small><noframes id='QS1JY'>

                        <i id='QS1JY'><tr id='QS1JY'><dt id='QS1JY'><q id='QS1JY'><span id='QS1JY'><b id='QS1JY'><form id='QS1JY'><ins id='QS1JY'></ins><ul id='QS1JY'></ul><sub id='QS1JY'></sub></form><legend id='QS1JY'></legend><bdo id='QS1JY'><pre id='QS1JY'><center id='QS1JY'></center></pre></bdo></b><th id='QS1JY'></th></span></q></dt></tr></i><div id='QS1JY'><tfoot id='QS1JY'></tfoot><dl id='QS1JY'><fieldset id='QS1JY'></fieldset></dl></div>

                          <tbody id='QS1JY'></tbody>
                        <tfoot id='QS1JY'></tfoot>
                          <bdo id='QS1JY'></bdo><ul id='QS1JY'></ul>